forked from tangotrail/catsite-stork-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
113 lines (85 loc) · 3.3 KB
/
bot.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
import discord
from discord.ext import commands
import json
import logging
import sys
logger = logging.getLogger('discord')
logger.setLevel(logging.INFO)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
prefix = '/'
intents = discord.Intents.all()
activity = discord.Game(name="Pixel Cat's End")
bot = commands.Bot(command_prefix=prefix, intents=intents, activity=activity)
mods = ['shops', 'items', 'cats', 'catsiteutil', 'shortcuts'] # modules
initial_extensions = mods
bot.remove_command("help")
with open('settings.json', 'r') as f:
content = json.load(f)
embed_color = int(content['color'][2:], base=16)
admin_ids = [int(discid) for discid in content['permissions']['admins']]
@bot.event
async def setup_hook():
for extension in initial_extensions:
await bot.load_extension(extension)
@bot.event
async def on_ready():
logger.info(f'Logged in as {bot.user.name}; ID {bot.user.id}')
@bot.command()
async def kill(ctx):
if ctx.message.author.id not in admin_ids:
logger.debug(
f'Attempted kill by {ctx.message.author.name} ({ctx.message.author.id}) with insufficient permissions')
return
embed = discord.Embed(description='Goodnight! Restarting soon.', colour=discord.Colour(embed_color))
await ctx.send(embed=embed)
await bot.logout()
sys.exit()
@bot.command(name="reloadall")
async def reload_all(ctx, *, _=""):
out = []
for extension_name in initial_extensions:
await bot.unload_extension(extension_name)
try:
await bot.load_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.send("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
out.append("**{}** loaded.".format(extension_name))
await ctx.send('\n'.join(out))
@bot.command()
async def load(ctx, extension_name: str):
try:
await bot.load_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.send("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
return
await ctx.send("**{}** loaded.".format(extension_name))
@bot.command()
async def unload(ctx, extension_name: str):
await bot.unload_extension(extension_name)
await ctx.send("**{}** unloaded.".format(extension_name))
@bot.command()
async def reload(ctx, extension_name: str):
await bot.unload_extension(extension_name)
try:
await bot.load_extension(extension_name)
except (AttributeError, ImportError) as e:
await ctx.send("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
return
await ctx.send("**{}** reloaded.".format(extension_name))
@bot.command()
async def color(ctx):
await ctx.send('#' + hex(embed_color)[2:])
def load_initial_extensions():
for extension in initial_extensions:
try:
# await bot.load_extension(extension)
logger.warning(f"Loaded {extension}")
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
logger.warning('Failed to load extension {}\n{}'.format(extension, exc))
if __name__ == "__main__":
with open('token.txt', 'r') as f:
token = f.read()
bot.run(token)