Add mail module
This commit is contained in:
parent
77e51c8229
commit
0792772c2a
3 changed files with 45 additions and 0 deletions
|
@ -24,6 +24,7 @@ cogs_list = [
|
||||||
'messages',
|
'messages',
|
||||||
'ksp',
|
'ksp',
|
||||||
'news',
|
'news',
|
||||||
|
'mail',
|
||||||
]
|
]
|
||||||
|
|
||||||
for cog in cogs_list:
|
for cog in cogs_list:
|
||||||
|
|
43
hrochobot/cogs/mail.py
Normal file
43
hrochobot/cogs/mail.py
Normal file
|
@ -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))
|
|
@ -2,4 +2,5 @@ TEMPLATES = {
|
||||||
'roles.json' : '{"secret_roles": {}}',
|
'roles.json' : '{"secret_roles": {}}',
|
||||||
'messages.json' : '{}',
|
'messages.json' : '{}',
|
||||||
'news.json' : '{}',
|
'news.json' : '{}',
|
||||||
|
'mails.json' : '{}',
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue