-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (49 loc) · 1.84 KB
/
main.py
File metadata and controls
62 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import discord
import os
import asyncio
from dotenv import load_dotenv
from send_email import send_email
from read_email import get_emails
load_dotenv() # load all the variables from the env file
bot = discord.Bot()
reading = False
@bot.event
async def on_ready():
print(f"{bot.user} is ready and online!")
@bot.slash_command(name="send", description="Send an email")
async def email(
ctx,
recipient_email: str,
subject: discord.Option(str, "Enter subject", required=False, default=None),
body: discord.Option(str, "Enter email body", required=False, default=None),
attachment: discord.Option(discord.SlashCommandOptionType.attachment, "Add attachments", required=False,
default=None)
):
await ctx.respond("Sending email...")
if send_email(recipient_email, subject, body, attachment):
await ctx.respond(f"Email sent to {recipient_email} with subject '{subject}'!")
else:
await ctx.respond(f"Something went wrong, please try again.")
@bot.slash_command(name="read", description="Read your Emails")
async def read(ctx):
global reading
reading = True
await ctx.respond("Reading emails...")
while reading:
email_data = get_emails()
print(email_data)
if email_data:
for mail in email_data:
message = f"{mail[0]}\n{mail[1]}\n\n{mail[2]}"
message = "%.2000s" % message
await ctx.respond(message)
await asyncio.sleep(10)
@bot.slash_command(name="stop", description="Stop Reading Emails")
async def stop(ctx):
global reading
if reading:
reading = False
await ctx.respond("Emails have been stopped")
else:
await ctx.respond("Emails are not currently being read!")
bot.run(os.getenv('TOKEN')) # run the bot with the token