-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
78 lines (63 loc) · 2.35 KB
/
bot.py
File metadata and controls
78 lines (63 loc) · 2.35 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
import aiohttp
import os
import pydest
import sys
import json
from app import run
from discord.ext import commands
from multiprocessing import Process
from pathlib import Path
from utils.custom_context import RandyContext
class Randy(commands.Bot):
def __init__(self, *args, **kwargs):
self.description = 'To be continued'
# Configs & token
with open('config.json') as f:
self.config = json.load(f)
super().__init__(command_prefix=commands.when_mentioned, description=self.description,
pm_help=None, *args, **kwargs)
# Startup extensions (none yet)
self.startup_ext = [x.stem for x in Path('cogs').glob('*.py')]
# aiohttp session
self.session = aiohttp.ClientSession(loop=self.loop)
# Make room for the help command
self.remove_command('help')
# Embed color
self.user_color = 0x781D1D
self.pyd = pydest.Pydest(self.config['key'])
self.fapp_proc = Process(target=run)
self.easy_access = {}
def run(self):
try:
self.fapp_proc.start()
super().run(self.config['token'])
finally:
self.fapp_proc.terminate()
self.loop.close()
async def report(self, msg):
await self.owner.send(f"Error, context: `{msg}`")
async def on_message(self, message):
if message.author.id == self.user.id:
return
await self.wait_until_ready()
ctx = await self.get_context(message, cls=RandyContext)
await self.invoke(ctx)
async def on_ready(self):
await self.pyd.update_manifest(language='en')
for ext in self.startup_ext:
try:
self.load_extension(f'cogs.{ext}')
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(f'Failed to load extension: {ext}\n{e}')
print(exc_type, fname, exc_tb.tb_lineno)
else:
print(f'Loaded extension: {ext}')
self.ses = aiohttp.ClientSession()
c = await self.application_info()
self.owner = c.owner
print(f'Client logged in.\n'
f'{self.user.name}\n'
f'{self.user.id}\n'
'--------------------------')