From ed9031a1d9b5057b5df1d468c9b45d5cf9aaad6f Mon Sep 17 00:00:00 2001 From: Akumatic Date: Sat, 26 Jan 2019 23:21:25 +0100 Subject: [PATCH] Messaging the bot redirects message to maintainer --- akuma.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/akuma.py b/akuma.py index 67f3732..d96c916 100644 --- a/akuma.py +++ b/akuma.py @@ -1,4 +1,4 @@ -import json, discord +import json, discord, io from discord.ext import commands from discord.ext.commands import CommandNotFound @@ -41,6 +41,41 @@ async def on_command_error(ctx, error): return raise error +@bot.event +async def on_message(message): + if message.guild == None and message.author.bot == False and message.content[:len(bot.command_prefix)] != bot.command_prefix: + user = bot.get_user(c["maintainer"]) + if user is not None: + e = discord.Embed(color=0xc83232) + e.set_author(name = str(message.author) + " sent a DM.", icon_url=message.author.avatar_url) + e.add_field(name="Profile", value=message.author.mention, inline=False) + if message.content: + e.add_field(name="Content", value=message.content, inline=False) + numAtch = len(message.attachments) + if numAtch == 0: + await user.send(embed=e) + elif numAtch == 1: + x = io.BytesIO() + await message.attachments[0].save(x) + name = message.attachments[0].filename + f = discord.File(x, filename = name) + extention = name.split(".")[-1] + if extention in ["jpg", "jpeg", "png", "webp", "gif"]: + e.set_image(url = "attachment://"+name) + await user.send(embed=e, file=f) + else: + e.add_field(name="Attachment",value=name, inline=False) + await user.send(embed=e) + await user.send(file=f) + else: + e.add_field(name="Attachments",value=str(numAtch)+" Attachments sent", inline=False) + await user.send(embed=e) + for a in message.attachments: + x = io.BytesIO() + await a.save(x) + await user.send(file=discord.File(x, filename=a.filename)) + await bot.process_commands(message) + @bot.command(hidden=True) async def printExt(ctx): """Prints out every loaded extension"""