-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (58 loc) · 1.9 KB
/
Copy pathmain.py
File metadata and controls
69 lines (58 loc) · 1.9 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
63
64
65
66
67
68
69
import discord
from discord import app_commands
import os
import requests
from dotenv import load_dotenv
load_dotenv()
#import tracemalloc #NEWLINE# tracemalloc.start()
TOKEN = os.getenv("TOKEN")
ALLOWED_USERS = [int(x.strip()) for x in os.getenv("ALLOWED_USERS").split(",")]
API_KEY = os.getenv("API_KEY")
DOMAIN = os.getenv("DOMAIN")
MAILCOW_URL = f"https://mail.{DOMAIN}/api/v1"
USER = os.getenv("USER")
MAILBOX = f"{USER}@{DOMAIN}"
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
clear_console() # Only for live Console
intents = discord.Intents.default()
intents.message_content = False
bot = discord.Client(intents=intents)
tree = app_commands.CommandTree(bot)
def create_email(name):
alias = f"{name}@{DOMAIN}"
data = {
"active": "1",
"address": alias,
"goto": MAILBOX,
"domain": DOMAIN
}
headers = {"X-API-Key": API_KEY,
"Content_Type": "application/json"}
r = requests.post(f"{MAILCOW_URL}/add/alias", json=data, headers=headers)
if r.status_code == 200:
if not r.text == "":
answer = f"Successfully created: {alias}!"
print(r.text)
else: answer = "Error: API request to Mailcow did not go through!"
else:
answer = f"Error {r.status_code}: {r.text}"
return answer
def create_email_test(name):
print(name)
return f"Successful! {name}"
@tree.command(
name="create_email",
description="Creates an Email Address",
)
async def create_email_command(interaction, message: str):
if interaction.user.id in ALLOWED_USERS:
await interaction.response.send_message(create_email(message), ephemeral=True)
else:
await interaction.response.send_message("You cannot access this command, sorry :(", ephemeral=True)
@bot.event
async def on_ready():
await tree.sync()
print('Command Tree synced!')
print('Ready!')
bot.run(TOKEN)