async def cdoGetUserPermissions(**kwargs): """ Gets the userlevel of a mentioned user :param kwargs: :return: """ data = list(kwargs['msg'].content.split(" ")) if len(kwargs['msg'].mentions) == 0: return CDOInteralResponseData("You need to mention a user to set its permission levels") for i in data: if i.startswith("<@"): del data[data.index(i)] if len(data) != 1: return CDOInteralResponseData("Wrong number of parameters. Needs !getUserPermissions *mentions* ") addInfo = OrderedDict() for user in kwargs['msg'].mentions: try: user = DiscordUsers.objects.get(id=user.id) addInfo[user.name] = f"User level: {user.userLevel}" except ObjectDoesNotExist: addInfo[user.name] = f"User level: 0" retObj = CDOInteralResponseData("UserLevels:") retObj.additionalInfo = addInfo return retObj
async def cdoUpcomingGames(**kwargs): """ Lists all upcoming games :param kwargs: :return: """ matchList = Scheduler.upcomingMatches() addInfo = OrderedDict() count = 0 addInfoList = [] for match in matchList: addInfo[match.title] = f"{match.match.date} (UTC)" count +=1 if count == 10: addInfoList.append(addInfo) addInfo = OrderedDict() count = 0 if addInfo != OrderedDict(): addInfoList.append(addInfo) if addInfoList == []: respStr = "No upcoming matches" else: respStr = "Upcoming matches:" resp = CDOInteralResponseData(respStr) if addInfoList != []: resp.additionalInfo = addInfoList[0] class pageContent: index = 0 @staticmethod def page(page): oldIndex = pageContent.index pageString = respStr + f" _(page {pageContent.index+1})_" if page == pageNav.forward: pageContent.index +=1 else: pageContent.index -=1 try: return CDOInteralResponseData(pageString,addInfoList[pageContent.index]) except IndexError: pageContent.index = oldIndex return CDOInteralResponseData(pageString, addInfoList[pageContent.index]) if addInfoList != []: resp.paging = pageContent.page return resp
async def cdoGetUserPermissions(msg : Message,**kwargs): """ Gets the userlevel of a mentioned user :param kwargs: :return: """ addInfo = InfoObj() for user in msg.mentions: try: user = DiscordUsers.objects.get(id=user.id) addInfo[user.name] = f"User level: {user.userLevel}" except ObjectDoesNotExist: addInfo[user.name] = f"User level: 0" if addInfo == InfoObj(): return CDOInteralResponseData("You need to mention a user to get its permission status!") retObj = CDOInteralResponseData("UserLevels:") retObj.additionalInfo = addInfo return retObj
async def cdoScores(msg : Message,**kwargs): """ Returns the scores for a given competition/matchday/team :param kwargs: :return: """ channel = msg.channel if "parameter0" not in kwargs.keys(): if not "live-" in channel.name: return CDOInteralResponseData(f"This command with no argument can only be called within matchday channels") comp,md = Scheduler.findCompetitionMatchdayByChannel(channel.name) matchList = Scheduler.getScores(comp,md) resp = CDOInteralResponseData("Current scores:") addInfo = InfoObj() for matchString,goalList in matchList.items(): addInfo[matchString] = "" for goals in goalList[0]: if goals != '': addInfo[matchString] += goals+"\n" if addInfo[matchString] == "": del addInfo[matchString] if addInfo == InfoObj(): addInfo[matchString] = f"{goalList[1]}: 0-0" if addInfo == InfoObj(): resp.response = "Currently no running matches" else: resp.response = "Current scores:" resp.additionalInfo = addInfo return resp else: searchString = kwargs['parameter0'] query = Competition.objects.filter(clear_name = searchString) if len(query) == 0: teamList = getTeamsSearchedByName(searchString) if len(teamList) == 0: return CDOInteralResponseData(f"Can't find team {searchString}") matchObj = teamList[0]['Name'][0]['Description'] matchList = getLiveMatches(teamID=int(teamList[0]["IdTeam"])) else: comp = query.first() matchObj = comp.clear_name matchList = getLiveMatches(competitionID=comp.id) if len(matchList) == 0: return CDOInteralResponseData(f"No current matches for {matchObj}") addInfo = InfoObj() for matchID in matchList: try: data = makeMiddlewareCall(DataCalls.liveData + f"/{matchID}") except JSONDecodeError: logger.error(f"Failed to do a middleware call for {matchID}") continue newEvents, _ = LiveMatch.parseEvents(data["match"]["events"], []) class Match: id = matchID for event in newEvents: title,_,goalListing = await LiveMatch.beautifyEvent(event,Match) if goalListing != "": try: addInfo[title]+=goalListing + "\n" except KeyError: addInfo[title] = goalListing + "\n" if addInfo == InfoObj(): return CDOInteralResponseData(f"No goals currently for {matchObj}") resp = CDOInteralResponseData(f"Current scores for {matchObj}") resp.additionalInfo = addInfo return resp