async def cdoListCompetitionByCountry(**kwargs): """ Lists all competitions for a given country. Needs the name of the country of country code as a parameter. :return: """ responseData = CDOInteralResponseData() data = kwargs['msg'].content.split(" ") if len(data) == 0: responseData.response = "List competition needs the country or countrycode as parameter" return responseData association = "" for i in data[1:]: if association == "": association += i else: association += " " + i competition = Competition.objects.filter(association__clear_name=association) if len(competition) == 0: competition = Competition.objects.filter(association_id=association) if len(competition) == 0: responseData.response = f"No competitions were found for {association}" return responseData retString = "Competitions:\n\n" compList = [] for comp in competition: retString += comp.clear_name + "\n" compList.append(f"{comp.clear_name}#{comp.association.id}") retString += f"\n\nReact with according number emoji to add competitions. Only the first {len(emojiList())} can " \ f"be added this way" responseData.response = retString def check(reaction, user): if reaction.emoji in emojiList(): try: index = emojiList().index(reaction.emoji) except ValueError: logger.error(f"{reaction.emoji} not in list!") return False if index < len(compList): kwargs['msg'].content = f"!addCompetition {compList[index]}" client.loop.create_task(cmdHandler(kwargs['msg'])) return True return False responseData.reactionFunc = check return responseData
async def cdoListCompetitionByCountry(msg : Message,**kwargs): """ Lists all competitions for a given country. Needs the name of the country of country code as a parameter. :return: """ responseData = CDOInteralResponseData() if "parameter0" not in kwargs.keys(): return CDOInteralResponseData(f"Needs the country or countrycode as parameter") association = kwargs['parameter0'] competition = Competition.objects.filter(association__clear_name=association) if len(competition) == 0: competition = Competition.objects.filter(association_id=association) if len(competition) == 0: responseData.response = f"No competitions were found for {association}" return responseData retString = "Competitions:\n\n" compList = [] for comp in competition: retString += comp.clear_name + "\n" compList.append(f"{comp.clear_name},{comp.association.id}") retString += f"\n\nReact with according number emoji to add competitions. Only the first {len(emojiList())} can " \ f"be added this way" responseData.response = retString def check(reaction: Reaction, user): if reaction.emoji in emojiList(): try: index = emojiList().index(reaction.emoji) except ValueError: logger.error(f"{reaction.emoji} not in list!") return False if index < len(compList): msg.content = f"{kwargs['prefix']}addCompetition {compList[index]}" client.loop.create_task(cmdHandler(msg)) return True responseData.reactionFunc = check return responseData
async def cdoStopBot(msg : Message,**kwargs): """ Stops the execution of the bot :param kwargs: :return: """ responseData = CDOInteralResponseData() retString = f"To confirm the shutdown, please react with {emojiList()[0]} to this message." responseData.response = retString def check(reaction : Reaction, user): if reaction.emoji == emojiList()[0]: client.loop.create_task(msg.channel.send("Bot is shutting down in 10 seconds")) client.loop.create_task(shutdown()) return True responseData.reactionFunc = check return responseData