def display_moves_by_frame(character, move_type, definition): if len(definition) < 2: result = embed.error_embed('Specify a ' + move_type.lower() + ' frame for ' + character['proper_name']) return result move_list = tkfinder.get_by_move_frame(character, move_type, definition) result = object if len(move_list) < 1: result = embed.error_embed('No ' + definition.lower() + ' moves for ' + character['proper_name']) elif len(move_list) == 1: character_move = tkfinder.get_move(character, move_list[0]) result = embed.move_embed(character, character_move) elif len(move_list) > 1: result = embed.move_list_embed(character, move_list, move_type) return result
def display_moves_by_type(character, move_type): move_list = tkfinder.get_by_move_type(character, move_type) result = object if len(move_list) < 1: result = embed.error_embed('No ' + move_type.lower() + ' for ' + character['proper_name']) elif len(move_list) == 1: character_move = tkfinder.get_move(character, move_list[0]) result = embed.move_embed(character, character_move) elif len(move_list) > 1: result = embed.move_list_embed(character, move_list, move_type) return result
def display_moves_by_type(character, move_type): move_list = tkfinder.get_by_move_type(character, move_type) result = {} if len(move_list) < 1: result["embed"] = embed.error_embed('No ' + move_type.lower() + ' for ' + character['proper_name']) elif len(move_list) == 1: character_move = tkfinder.get_move(character, move_list[0]) if character_move and "Tags" in character_move: result["components"] = ActionRow(create_components(character_move)) result["embed"] = embed.move_embed(character, character_move) elif len(move_list) > 1: result["embed"] = embed.move_list_embed(character, move_list, move_type) return result
step = 60 for begin in range(0, len(serverlist), step): end = begin + step if end > len(serverlist): end = len(serverlist) servers = reduce(util.do_sum, serverlist[begin:end]) await channel.send(servers) msg = "Number of servers in: " + str(len(serverlist)) await channel.send(msg) elif message.content == '!last-updates': try: messages = util.get_latest_commits_messages(gh, 5) result = {"embed": embed.success_embed(messages)} except Exception as e: result = {"embed": embed.error_embed(e)} await channel.send(embed=result) elif message.content.startswith("!auto-delete"): if message.author.permissions_in(channel).manage_messages: duration = message.content.split(' ', 1)[1] if duration.isdigit() or duration == "-1": config.save_auto_delete_duration(channel.id, duration) result = {"embed": embed.success_embed("Saved")} else: result = {"embed": embed.error_embed("Duration needs to be a number in seconds")} else: result = {"embed": embed.error_embed("You need the permission <manage_messages> to do that")} await channel.send(embed=result["embed"])
async def on_message(message): """This has the main functionality of the bot. It has a lot of things that would be better suited elsewhere but I don't know if I'm going to change it.""" try: channel = message.channel if str(message.author) in const.BLACKLIST: return if message.content == '!server-list': serverlist = list(map(lambda x: x.name, bot.guilds)) serverlist.sort() step = 60 for begin in range(0, len(serverlist), step): end = begin + step if end > len(serverlist): end = len(serverlist) servers = reduce(util.do_sum, serverlist[begin:end]) await channel.send(servers) msg = "Number of servers in: " + str(len(serverlist)) await channel.send(msg) elif message.content == '!last-updates': try: messages = util.get_latest_commits_messages(gh, 5) result = embed.success_embed(messages) except Exception as e: result = embed.error_embed(e) await channel.send(embed=result) elif message.content.startswith("!auto-delete"): if message.author.permissions_in(channel).manage_messages: duration = message.content.split(' ', 1)[1] if duration.isdigit() or duration == "-1": config.save_auto_delete_duration(channel.id, duration) result = embed.success_embed("Saved") else: result = embed.error_embed( "Duration needs to be a number in seconds") else: result = embed.error_embed( "You need the permission <manage_messages> to do that") await channel.send(embed=result) elif message.content.startswith('!clear-messages'): # delete x of the bot last messages number = int(message.content.split(' ', 1)[1]) messages = [] async for m in channel.history(limit=100): if m.author == bot.user: messages.append(m) to_delete = [message] for i in range(number): to_delete.append(messages[i]) await channel.delete_messages(to_delete) elif message.content == '!help': await channel.send(embed=embed.help_embed()) elif message.content.startswith('?feedback'): user_message = message.content.split(' ', 1)[1].replace("\n", "") server_name = str(message.channel.guild) feedback_channel = bot.get_channel(feedback_channel_id) try: feedback_message = "{} ; {} ; {};\n".format( str(message.author), server_name, user_message) await feedback_channel.send(feedback_message) result = embed.success_embed("Feedback sent") except Exception as e: result = embed.error_embed( "Feedback couldn't be sent caused by: " + e) await channel.send(embed=result) elif message.content.startswith('!') and len(message.content[1:].split( ' ', 1)) > 1 and not message.content.startswith('!wiki'): delete_after = None user_message_list = message.content[1:].split(' ', 1) original_name = user_message_list[0].lower() original_move = user_message_list[1] character_name = tkfinder.correct_character_name(original_name) if character_name is not None: character = tkfinder.get_character_detail(character_name) move_type = util.get_move_type(original_move.lower()) if move_type: result = util.display_moves_by_type(character, move_type) else: result = util.display_moves_by_input( character, original_move) else: result = embed.error_embed( f'Character {original_name} does not exist.') delete_after = None bot_message = await channel.send(embed=result, delete_after=delete_after) if embed.MOVE_NOT_FOUND_TITLE == bot_message.embeds[0].title: content = bot_message.embeds[0].description.replace( '\n', '\\n').split("\\n") movelist = util.get_moves_from_content(content) for i in range(len(movelist)): await bot_message.add_reaction(const.EMOJI_LIST[i]) await bot.process_commands(message) except Exception as e: time_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") error_msg = f'{time_now} | Message: {message.content} from {message.author.name} in {message.channel.guild.name}.' \ f'\n Error: {e}' print(error_msg) logger.error(error_msg)
async def on_message(message): """This has the main functionality of the bot. It has a lot of things that would be better suited elsewhere but I don't know if I'm going to change it.""" try: channel = message.channel if message.content == "?credit": await channel.send(embed=embed.thank_embed()) return elif message.content == '!help': await channel.send(embed=embed.help_embed()) return elif message.content == '!clear-messages': await channel.purge(limit=200, check=is_me) return elif message.content.startswith('?feedback'): user_message = message.content.split(' ', 1)[1] server_name = str(message.channel.guild) try: feedback_channel = bot.get_channel(const.FEEDBACK_CHANNEL_ID) user_message = user_message.replace("\n", "") result = "{} ; {} ; {};\n".format(str(message.author), server_name, user_message) await feedback_channel.send(result) await channel.send(embed=embed.success_embed("Feedback sent")) except Exception as e: await channel.send(embed=embed.error_embed( "Feedback couldn't be sent caused by: " + e)) return elif message.content.startswith('!'): delete_after = 20 if ('tekken' in channel.name) or ('frame' in channel.name): delete_after = None user_message = message.content command = user_message[1:] user_message_list = command.split(' ', 1) if len(user_message_list) <= 1: # malformed command return original_name = user_message_list[0].lower() original_move = user_message_list[1] character_name = tkfinder.correct_character_name(original_name) if character_name is not None: character = tkfinder.get_character_data(character_name) character_move = original_move.lower() if original_move.lower() in const.MOVE_TYPES.keys(): move_list = tkfinder.get_by_move_type( character, const.MOVE_TYPES[character_move]) if len(move_list) < 1: result = embed.error_embed( 'No ' + const.MOVE_TYPES[character_move].lower() + ' for ' + character['proper_name']) await channel.send(embed=result, delete_after=delete_after) elif len(move_list) == 1: character_move = tkfinder.get_move( character, move_list[0]) result = embed.move_embed(character, character_move) await channel.send(embed=result, delete_after=delete_after) elif len(move_list) > 1: result = embed.move_list_embed( character, move_list, const.MOVE_TYPES[character_move]) await channel.send(embed=result, delete_after=delete_after) else: character_move = tkfinder.get_move(character, original_move) # First checks the move as case sensitive, if it doesn't find it # it checks it case insensitive if character_move is not None: result = embed.move_embed(character, character_move) await channel.send(embed=result, delete_after=delete_after) else: character_move = tkfinder.get_move( character, original_move) if character_move is not None: result = embed.move_embed(character, character_move) await channel.send(embed=result, delete_after=delete_after) else: similar_moves = tkfinder.get_similar_moves( original_move, character_name) result = embed.similar_moves_embed(similar_moves) await channel.send(embed=result, delete_after=delete_after) else: bot_msg = f'Character {original_name} does not exist.' result = embed.error_embed(bot_msg) await message.channel.send(embed=result, delete_after=5) return await bot.process_commands(message) except Exception as e: print(e) logger.error(e)
async def on_message(message): """This has the main functionality of the bot. It has a lot of things that would be better suited elsewhere but I don't know if I'm going to change it.""" try: channel = message.channel if message.content.startswith("!auto-delete"): if message.author.permissions_in(channel).manage_messages: duration = message.content.split(' ', 1)[1] if duration.isdigit() or duration == "-1": config.save_auto_delete_duration(channel.id, duration) await channel.send(embed=embed.success_embed("Saved")) else: await channel.send(embed=embed.error_embed( "Duration needs to be a number in seconds")) else: await channel.send(embed=embed.error_embed( "You need the permission <manage_messages> to do that")) return elif message.content == '!help': await channel.send(embed=embed.help_embed()) return elif message.content.startswith('?feedback'): user_message = message.content.split(' ', 1)[1] server_name = str(message.channel.guild) try: feedback_channel = bot.get_channel(feedback_channel_id) user_message = user_message.replace("\n", "") result = "{} ; {} ; {};\n".format(str(message.author), server_name, user_message) await feedback_channel.send(result) await channel.send(embed=embed.success_embed("Feedback sent")) except Exception as e: await channel.send(embed=embed.error_embed( "Feedback couldn't be sent caused by: " + e)) return elif message.content.startswith('!'): delete_after = config.get_auto_delete_duration(channel.id) user_message = message.content command = user_message[1:] user_message_list = command.split(' ', 1) if len(user_message_list) <= 1: # malformed command return original_name = user_message_list[0].lower() original_move = user_message_list[1] character_name = tkfinder.correct_character_name(original_name) if character_name is not None: character = tkfinder.get_character_data(character_name) character_move = original_move.lower() if original_move.lower() in const.MOVE_TYPES.keys(): move_list = tkfinder.get_by_move_type( character, const.MOVE_TYPES[character_move]) if len(move_list) < 1: result = embed.error_embed( 'No ' + const.MOVE_TYPES[character_move].lower() + ' for ' + character['proper_name']) await channel.send(embed=result, delete_after=delete_after) elif len(move_list) == 1: character_move = tkfinder.get_move( character, move_list[0]) result = embed.move_embed(character, character_move) await channel.send(embed=result, delete_after=delete_after) elif len(move_list) > 1: result = embed.move_list_embed( character, move_list, const.MOVE_TYPES[character_move]) await channel.send(embed=result, delete_after=delete_after) else: character_move = tkfinder.get_move(character, original_move) if character_move is not None: result = embed.move_embed(character, character_move) await channel.send(embed=result, delete_after=delete_after) else: similar_moves = tkfinder.get_similar_moves( original_move, character_name) result = embed.similar_moves_embed(similar_moves) await channel.send(embed=result, delete_after=delete_after) else: bot_msg = f'Character {original_name} does not exist.' result = embed.error_embed(bot_msg) await message.channel.send(embed=result, delete_after=5) return await bot.process_commands(message) except Exception as e: error_msg = f'Message: {message.content}. Error: {e}' print(error_msg) logger.error(error_msg)