Browse Source

Add mail module

mail
Daniel Skýpala 6 months ago
parent
commit
0792772c2a
  1. 1
      bin/hrochobot
  2. 43
      hrochobot/cogs/mail.py
  3. 1
      hrochobot/utils/json_templates.py

1
bin/hrochobot

@ -24,6 +24,7 @@ cogs_list = [
'messages',
'ksp',
'news',
'mail',
]
for cog in cogs_list:

43
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))

1
hrochobot/utils/json_templates.py

@ -2,4 +2,5 @@ TEMPLATES = {
'roles.json' : '{"secret_roles": {}}',
'messages.json' : '{}',
'news.json' : '{}',
'mails.json' : '{}',
}

Loading…
Cancel
Save