async def on_message(self, message): if message.guild is None: return elif message.guild.id != constants.tortoise_guild_id: return if not message.author.bot and len( message.content) > constants.max_message_length: # Below part is when someone sends too long message, bot will recommend them to use our pastebin # TODO we are skipping message deletion for now until we implement system to check # if sent message is code or not msg = ( "Your message is quite long.\n" f"You should consider using our paste service {constants.tortoise_paste_service_link}" ) await message.channel.send(embed=warning(msg)) if message.channel.id == constants.suggestions_channel_id: if (message.author == self.bot.user and message.embeds and message.embeds[0].description == self.SUGGESTION_MESSAGE_CONTENT): await self.bot.api_client.edit_suggestion_message_id(message.id ) else: old_suggestion_msg_id = await self.bot.api_client.get_suggestion_message_id( ) try: old_message = await message.channel.fetch_message( old_suggestion_msg_id) except discord.NotFound: pass else: await old_message.delete() await self.create_new_suggestion_message()
async def manually_add_database_member(self, ctx, member: Member): if await self.bot.api_client.does_member_exist(member.id): await ctx.send(embed=warning("Member already exists, aborting..")) return logger.info(f"{ctx.author} is manually adding member {member} {member.id} to database") await self.bot.api_client.insert_new_member(member) await ctx.send(embed=success(f"Member {member} successfully added to database."))
async def on_message(self, message): if message.guild is None: return elif message.guild.id != constants.tortoise_guild_id: return elif message.author.bot: return if len(message.content) > constants.max_message_length: # TODO we are skipping message deletion for now until we implement system to check # if sent message is code or not msg = ( "Your message is quite long.\n" f"You should consider using our paste service {constants.tortoise_paste_service_link}" ) await message.channel.send(embed=warning(msg))
async def _deal_with_attachments(self, message: Message): for attachment in message.attachments: try: extension = attachment.filename.rsplit('.')[1] except IndexError: extension = None if extension not in allowed_file_extensions: await message.delete() reply = ( f"It looks like you tried to attach a {extension} file which is not allowed, " "as it could potentially contain malicious code.") if extension in extension_to_pastebin: file_content = await attachment.read() url = await self.create_pastebin_link(file_content) reply += f"\n\nYou can find the file paste here:\n[**{attachment.filename}** {url}]" await message.channel.send(f"Hey {message.author.mention}!", embed=warning(reply))
async def _deal_with_invites(self, message: Message): base_url = re.findall( r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", # Find any url message.content) for invite in base_url: # Get the endpoint of that url (for discord invite url shorteners) try: async with self.session.get(invite) as response: invite = str(response.url) except aiohttp.ClientConnectorError: # The link is not valid continue if "discord.com/invite/" in invite or "discord.gg/" in invite: if not await Security.check_if_invite_is_our_guild( invite, message.guild): # TODO give him warning points etc / send to deterrence channel embed = warning( f"{message.author.mention} You are not allowed to send other server invites here." ) await message.channel.send(embed=embed) await message.delete()