-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (62 loc) · 2.75 KB
/
Copy pathmain.py
File metadata and controls
80 lines (62 loc) · 2.75 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
70
71
72
73
74
75
76
77
78
79
80
import discord
import os
from apis.dbd import DbdApi
from apis.steam import SteamApi
from commands.command_utils import CommandUtils
from commands.screams import Screams
from commands.escapes import Escapes
from commands.stats import Stats
from commands.randomize import Randomize
from commands.survivor import Survivor
from commands.killer import Killer
DBD = DbdApi()
STEAM = SteamApi()
UTILS = CommandUtils()
class DBDInfoClient(discord.Client):
commands = {
"-stats":Stats(STEAM, UTILS),
"-survivor":Survivor(STEAM, UTILS),
"-escapes":Escapes(STEAM, DBD, UTILS),
"-killer":Killer(STEAM, UTILS),
"-randomize":Randomize(DBD, UTILS),
"-screams":Screams(STEAM),
}
async def on_ready(self):
print(f'Logged on as {self.user}!')
# Not sure if this is the best way to handle the utils methods
UTILS.set_pfp_url(self.user.display_avatar.url)
async def on_message(self, message):
text = message.content
if text.startswith("-") and len(text) > 1 and text[1].isalpha():
args = text.split()
arg_count = len(args)
response = [None, None, None, None]
# Help Command
if args[0] == "-help":
embed = UTILS.make_embed(UTILS.Color.NEUTRAL)
embed.title = "DBD Info Bot Commands"
embed.set_thumbnail(url=UTILS.pfp_url)
for cmd in DBDInfoClient.commands.values():
embed.add_field(
name=cmd.name,
value=cmd.description + "\nUsage: " + cmd.usage,
inline=False)
response[1] = embed
# Check if the command is valid
elif args[0] not in DBDInfoClient.commands:
response[0] = "Command " + args[0] + " not found!"
else:
command = DBDInfoClient.commands[args[0]]
# Check if the proper number of arguments was given
# Every command must have a field called num_args
if arg_count < command.num_args:
response[0] = f"Missing arguments:\n\tUsage: " + command.usage
else:
# Every command must have a run function that takes an array of arguments
# and returns a array that contains [message text, embed, embed_list, files_list], only one of which needs a value
response = command.run(args)
await message.channel.send(content=response[0], embed=response[1], embeds=response[2], files=response[3])
intents = discord.Intents.default()
intents.message_content = True
client = DBDInfoClient(intents=intents)
client.run(os.getenv('DISCORD_TOKEN'))