diff --git a/README.md b/README.md index e87aa6b..03b1ae3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ cah - Cards Against Humanity. A port of CorpBot's module: https://github.com/cor chatchart - Generates a pie chart to display chat activity over the last 5000 messages. Requested by violetnyte. +forwarding - Forwards DMs sent to the bot to the owner of the bot. A port of the forwarding module from: https://github.com/jacobcheatley/dankbot + hunting - By Paddolicious#8880. It hunts birds... and things that fly. imgwelcome - Welcome users to your server with a customized image. diff --git a/forwarding/forwarding.py b/forwarding/forwarding.py new file mode 100644 index 0000000..1239dff --- /dev/null +++ b/forwarding/forwarding.py @@ -0,0 +1,49 @@ +# forwarding.py is ported from another bot: +# https://github.com/jacobcheatley/dankbot + +import discord +from discord.ext import commands +from .utils.dataIO import dataIO +from .utils import checks + + +class Forwarding: + def __init__(self, bot: commands.Bot): + self.bot = bot + self.owner = self.get_owner() + + def get_owner(self): + owner_id = dataIO.load_json("data/red/settings.json")["OWNER"] + return discord.utils.find(lambda m: m.id == owner_id, self.bot.get_all_members()) + + async def send_to_owner(self, **kwargs): + if self.owner is None: + self.owner = self.get_owner() + await self.bot.send_message(self.owner, **kwargs) + + async def on_message(self, message: discord.Message): + if self.owner is None: + self.owner = self.get_owner() + if not message.channel.is_private or message.channel.user.id == self.owner.id: + return + + embed = discord.Embed() + if message.author == self.bot.user: + embed.title = 'Sent PM to {}#{} ({}).'.format(message.channel.user.name, message.channel.user.discriminator, message.channel.user.id) + else: + embed.set_author(name=message.author, icon_url=message.author.avatar_url or message.author.default_avatar_url) + embed.title = '{} messaged me:'.format(message.channel.user.id) + embed.description = message.content + embed.timestamp = message.timestamp + + await self.send_to_owner(embed=embed) + + @commands.command() + @checks.is_owner() + async def pm(self, user: discord.User, *, content: str): + """PMs a person.""" + await self.bot.send_message(user, content) + + +def setup(bot): + bot.add_cog(Forwarding(bot)) diff --git a/forwarding/info.json b/forwarding/info.json new file mode 100644 index 0000000..b040c7d --- /dev/null +++ b/forwarding/info.json @@ -0,0 +1,7 @@ +{ + "AUTHOR" : "aikaterna", + "NAME" : "forwarding", + "SHORT" : "Forwards DMs sent to the bot to the owner.", + "DESCRIPTION" : "Forwards DMs sent to the bot to the owner.", + "TAGS": ["message", "dm"] +}