forked from sinus-x/discord-wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
112 lines (84 loc) · 2.67 KB
/
init.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
import json
import traceback
from datetime import datetime
import discord
from discord.ext import commands
from core import wormcog, output, checks
config = json.load(open("config.json"))
intents = discord.Intents.none()
intents.guilds = True # Needed for on_guild_join() and Info cog commands
intents.members = True
# FIXME Do we need member cache? We only use it for whois and tag translation
intents.emojis = True # Needed to translate unavailable emojis
intents.messages = True # Core functionality
bot = commands.Bot(
command_prefix=config["prefix"],
help_command=None,
allowed_mentions=discord.AllowedMentions(roles=False, everyone=False, users=True),
intents=intents,
)
event = output.Event(bot)
##
## EVENTS
##
started = False
@bot.event
async def on_ready():
global started
if not started:
m = "INFO: Ready at " + datetime.today().strftime("%Y-%m-%d %H:%M:%S")
started = True
else:
m = "Reconnected: " + datetime.today().strftime("%Y-%m-%d %H:%M:%S")
print(m)
ch = bot.get_channel(config["log channel"])
await ch.send(f"```{m}```")
await wormcog.presence(bot)
@bot.event
async def on_error(event, *args, **kwargs):
if config["log level"] == "CRITICAL":
return
tb = traceback.format_exc()
print(tb)
channel = bot.get_channel(config["log channel"])
if channel is None:
print("ERROR: Error channel not found")
return
output = list(tb[0 + i : 1980 + i] for i in range(0, len(tb), 1980))
for o in output:
await channel.send(f"```{o}```")
##
## COMMANDS
##
@bot.command()
@commands.check(checks.is_admin)
async def load(ctx: commands.Context, cog: str):
"""Load module"""
bot.load_extension(f"cogs.{cog}")
await ctx.send(f"**{cog.upper()}** loaded.")
await event.sudo(ctx, f"Loaded: {cog.upper()}")
print(f"{cog.upper()} loaded")
@bot.command()
@commands.check(checks.is_admin)
async def reload(ctx: commands.Context, cog: str):
"""Reload module"""
bot.reload_extension(f"cogs.{cog}")
await ctx.send(f"**{cog.upper()}** reloaded.")
await event.sudo(ctx, f"Reloaded: {cog.upper()}")
print(f"{cog.upper()} reloaded")
@bot.command()
@commands.check(checks.is_admin)
async def unload(ctx: commands.Context, cog: str):
"""Unload module"""
bot.unload_extension(f"cogs.{cog}")
await ctx.send(f"**{cog.upper()}** unloaded.")
await event.sudo(ctx, f"Unloaded: {cog.upper()}")
print(f"{cog.upper()} unloaded")
##
## INIT
##
bot.load_extension("cogs.errors")
for c in ["wormhole", "admin", "user", "notifications", "info"]:
bot.load_extension(f"cogs.{c}")
print(f"{c.upper()} loaded")
bot.run(config.get("bot key"))