diff --git a/bin/hrochobot b/bin/hrochobot index 729e853..35ee74b 100755 --- a/bin/hrochobot +++ b/bin/hrochobot @@ -24,6 +24,7 @@ cogs_list = [ 'messages', 'ksp', 'news', + 'mail', ] for cog in cogs_list: diff --git a/hrochobot/cogs/mail.py b/hrochobot/cogs/mail.py new file mode 100644 index 0000000..fc8f5a3 --- /dev/null +++ b/hrochobot/cogs/mail.py @@ -0,0 +1,43 @@ +import discord +from discord.ext import commands +from discord.utils import get +import hrochobot.utils.data as data + +MAILS_JSON = "mails" + +class Mail(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @discord.message_command() + async def mail(self, ctx: discord.Interaction, message: discord.Message): + mails_json = data.load_data(MAILS_JSON) + if str(ctx.author.id) not in mails_json: + return await ctx.respond(f"Mail not set.", ephemeral=True) + mail = mails_json[str(ctx.author.id)] + + if message.author.nick: + header = f"{message.author.nick} ({message.author})" + else: + header = f"{message.author}" + + time = message.created_at.strftime("%Y-%m-%d %H:%M:%S") + header += f" wrote on {time} in channel '{message.channel}' server '{message.guild}':" + + # TODO: Send mail here + print(mail) + print(f"{header}\n{message.jump_url}\n\n{message.content}") + + return await ctx.respond("Message sent to email.", ephemeral=True) + + @discord.slash_command(description="Sets mail for sending emails.") + @discord.option("mail", str, description="Mail to set.") + async def set_mail(self, ctx: discord.Interaction, mail: str): + mails_json = data.load_data(MAILS_JSON) + mails_json[ctx.author.id] = mail + data.dump_data(MAILS_JSON, mails_json) + return await ctx.respond(f"Mail set to ``{mail}``.", ephemeral=True) + + +def setup(bot): + bot.add_cog(Mail(bot)) diff --git a/hrochobot/utils/json_templates.py b/hrochobot/utils/json_templates.py index e7ce0e5..291a7ce 100644 --- a/hrochobot/utils/json_templates.py +++ b/hrochobot/utils/json_templates.py @@ -2,4 +2,5 @@ TEMPLATES = { 'roles.json' : '{"secret_roles": {}}', 'messages.json' : '{}', 'news.json' : '{}', + 'mails.json' : '{}', }