async def logCommandSent(messagecontext): # log to the command log of the guild enabled = await loggingEnabled(messagecontext.message) guild = messagecontext.guild() log_path = f'logs/guilds/{guild.id}/commands.log' if enabled: log_message = f'{messagecontext.readable_log()}\n' write_log_message(log_message, log_path)
async def checkMessage(messagecontext): # split message into an array to check individual words words = messagecontext.message_words() message = messagecontext.message lowered_content = message.content.lower() # reactions if settings.get_boolean_value(messagecontext.guild_id(), 'reactions', True): # react to these terms if 'catgirl' in lowered_content or 'neko' in lowered_content or 'sex' in lowered_content: await message.add_reaction('<:wooaaahhh:789297106837569557>' ) #wooaaahhh # gm gn reacts if 'gm' in words or 'gn' in words: if 'gm' in words: await message.add_reaction('<:catgm:782652523462393918>') if 'gn' in words: await message.add_reaction('<:catgn:782652492847775794>') if 'i love you' in lowered_content: await message.add_reaction('<:love:794076402945228811>') # respond to pings if cfg.bot.user in message.mentions: await message.channel.send(owouwu.gen()) # check filters # exempt users with no filter role if messagecontext.guild().get_role( settings.get_integer_value(messagecontext.guild_id(), 'filterrole')) in message.author.roles: return filtered = await breaks_filter(messagecontext) if filtered: await messagecontext.channel().send( content=f'{message.author.mention}, that word is not allowed here!', delete_after=10) try: await messagecontext.message.delete() except: print( f'Failed to delete message in guild {messagecontext.guild().name}' )
async def logChatMessage(messagecontext): # write message to a file if the option is on enabled = await loggingEnabled(messagecontext.message) channel = messagecontext.channel() guild = messagecontext.guild() if enabled: section_folder = f'logs/guilds/{guild.id}/{channel.category.id}' make_dir_if_needed(section_folder) log_path = f'{section_folder}/{channel.id}.log' try: log_message = f'{messagecontext.readable_log()}\n' write_log_message(log_message, log_path) except: log_message = f'{messagecontext.log_header()}: Unable to log contents, exception occured\n' write_log_message(log_message, log_path)
async def logMessagedDeleted(messagecontext): # args should be of type message context enabled = await loggingEnabled(messagecontext.message) if not enabled: return guild = messagecontext.guild() log_message = f'{messagecontext.log_header()} deleted message: {messagecontext.message.content}\n\n' log_path = f'logs/guilds/{guild.id}/messages_changed.log' discord_message = { 'Author': messagecontext.readable_author(), 'Message': messagecontext.message.content } write_log_message(log_message, log_path) await send_discord_log_message(messagecontext, discord_message, 'Deleted Message')
async def send_discord_log_message(messagecontext, log_dict, title): if messagecontext.author() == cfg.bot.user: return guild_id = messagecontext.guild_id() pfp_url = messagecontext.author().avatar_url channel_id = settings.get_integer_value(guild_id, 'logchannel') channel = messagecontext.guild().get_channel(channel_id) embed_wrapper = discord.Embed(colour=0xFB98FB) embed_wrapper.set_author(name=title, url='https://github.com/Burrit0z/catgirl-bot', icon_url=pfp_url) for key in log_dict.keys(): embed_wrapper.add_field(name=key, value=log_dict[key], inline=False) try: await channel.send(embed=embed_wrapper) except: pass