This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
187 lines (143 loc) · 4.94 KB
/
main.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import discord
from discord.ext import commands, tasks
import logging
from itertools import cycle
import os
import os.path
import json
from discord_slash import SlashCommand
import random
from dotenv import dotenv_values
import sentry_sdk
# TOKEN stuff
config = dotenv_values(".env")
if "DISCORD_TOKEN" not in config:
DISCORD_TOKEN = os.environ["DISCORD_TOKEN"]
else:
DISCORD_TOKEN = config["DISCORD_TOKEN"]
if "GITHUB_TOKEN" not in config:
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
else:
GITHUB_TOKEN = config["GITHUB_TOKEN"]
if "SHORTIO_TOKEN" not in config:
SHORTIO_TOKEN = os.environ["SHORTIO_TOKEN"]
else:
SHORTIO_TOKEN = config["SHORTIO_TOKEN"]
if "SENTRY_URL" not in config:
SENTRY_URL = os.environ["SENTRY_URL"]
else:
SENTRY_URL = config["SENTRY_URL"]
if "STATCORD_TOKEN" not in config:
STATCORD_TOKEN = os.environ["STATCORD_TOKEN"]
else:
STATCORD_TOKEN = config["STATCORD_TOKEN"]
# Sentry-stuff
sentry_sdk.init(SENTRY_URL, traces_sample_rate=1.0)
# CONFIGURATION
logging.basicConfig(
format='%(asctime)s: %(levelname)s: %(message)s',
datefmt='%Y-%m-%d; %H:%M:%S',
level=logging.INFO
)
intents = discord.Intents.all()
test_guilds = [707243781946343425]
client = commands.Bot(command_prefix="-", intents = intents)
client.remove_command('help')
slash = SlashCommand(client, sync_commands = True)
statusmessages = ["Slash Commands", 'navnlos.ml', 'nvnls.ml/support']
statusmsg = cycle(statusmessages)
# a universal embed used in all try...except blocks
error_msgs = [
"Something really bad happened!",
"That shouldn't have happened",
"So you've caused an error...",
"That didn't go so well..."
]
async def make_error_embed(exception):
logging.warn(f"An error occured!\nERROR: {exception}")
embed = discord.Embed(
title = str(random.choice(error_msgs)),
description = f"```\n{exception}```",
color = discord.Color.red()
)
embed.set_footer(text = "If you need help, join our support server! discord.gg/52TbNHPBU9")
return embed
# END OF CONFIGURATION STUFF
@client.event
async def on_ready():
change_status.start()
logging.info("Bot is online.")
owner = client.get_user(586206645592391711)
await owner.send("Online!")
@tasks.loop(seconds=20)
async def change_status():
newstatus = next(statusmsg)
await client.change_presence(
status=discord.Status.online,
activity=discord.Activity(
type=discord.ActivityType.listening,
name= newstatus
)
)
#logging.info(f"Changed activity to \"{newstatus}\"")
@client.command()
@commands.is_owner()
async def load(ctx, extension):
try:
client.load_extension(extension)
await ctx.reply(f"Extension `{str(extension)}` loaded")
logging.info(f"Extension \"{str(extension)}\" loaded.")
except Exception as e:
embed = await make_error_embed(e)
await ctx.reply(embed = embed)
@client.command()
@commands.is_owner()
async def unload(ctx, extension):
try:
client.unload_extension(extension)
await ctx.reply(f"Extension `{str(extension)}` unloaded")
logging.info(f"Extension \"{str(extension)}\" unloaded.")
except Exception as e:
embed = await make_error_embed(e)
await ctx.reply(embed = embed)
@client.command()
@commands.is_owner()
async def reload(ctx, extension):
try:
client.unload_extension(extension)
client.load_extension(extension)
await ctx.reply(f"Extension `{str(extension)}` reloaded")
logging.info(f"Extension \"{str(extension)}\" reloaded.")
except Exception as e:
embed = await make_error_embed(e)
await ctx.reply(embed = embed)
# load all cogs
for filename in os.listdir("./auto_publisher"):
if filename.endswith(".py"):
client.load_extension(f"auto_publisher.{filename[:-3]}")
for filename in os.listdir("./fun"):
if filename.endswith(".py"):
client.load_extension(f"fun.{filename[:-3]}")
for filename in os.listdir("./member_actions"):
if filename.endswith(".py"):
client.load_extension(f"member_actions.{filename[:-3]}")
for filename in os.listdir("./moderation"):
if filename.endswith(".py"):
client.load_extension(f"moderation.{filename[:-3]}")
for filename in os.listdir("./role_menu"):
if filename.endswith(".py"):
client.load_extension(f"role_menu.{filename[:-3]}")
for filename in os.listdir("./system"):
if filename.endswith(".py"):
client.load_extension(f"system.{filename[:-3]}")
for filename in os.listdir("./tools"):
if filename.endswith(".py"):
client.load_extension(f"tools.{filename[:-3]}")
for filename in os.listdir("./vc_role"):
if filename.endswith(".py"):
client.load_extension(f"vc_role.{filename[:-3]}")
for filename in os.listdir("./log_system"):
if filename.endswith(".py"):
client.load_extension(f"log_system.{filename[:-3]}")
if __name__ == "__main__":
client.run(DISCORD_TOKEN)