-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
86 lines (66 loc) · 2.43 KB
/
bot.py
File metadata and controls
86 lines (66 loc) · 2.43 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
81
82
83
84
85
86
# IMPORTS
import discord
import json
import datetime
import aiohttp
import asyncpg
from discord.ext import commands
from utils.views import AccessRoles, CharlesNews, ApiNews, GamesNews
print('[CONNECT] Logging in...')
class CTX(commands.Context):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@property
def replied_reference(self):
ref = self.message.reference
if ref and isinstance(ref.resolved, discord.Message):
return ref.resolved.to_reference()
return None
class Alfred(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!",
reconnect=True,
case_insensitive=True,
intents=discord.Intents.all(),
member_cache_flags=discord.MemberCacheFlags.all(),
owner_ids=[171539705043615744, 547861735391100931],
slash_command_guilds=[514232441498763279])
# Bot vars
self.requests = {}
with open("config.json") as f:
self.config = json.load(f)
for ext in ['cogs.help', 'cogs.owner', 'jishaku', 'cogs.devision', 'cogs.tags', 'cogs.reports']:
self.load_extension(ext)
async def on_message(self, msg):
if not self.is_ready() or msg.author.bot:
return
await self.process_commands(msg)
async def on_ready(self):
print(f'[CONNECT] Logged in as:\n{self.user} (ID: {self.user.id})\n')
if not hasattr(self, 'uptime'):
self.uptime = datetime.datetime.utcnow()
async def setup(self):
self.add_view(AccessRoles())
self.add_view(CharlesNews())
self.add_view(GamesNews())
self.add_view(ApiNews())
await super().setup()
def run(self):
loop = self.loop
try:
loop.run_until_complete(self.bot_start())
except KeyboardInterrupt:
loop.run_until_complete(self.bot_logout())
async def bot_logout(self):
await self.session.close()
await self.db.close()
await super().close()
async def bot_start(self):
self.session = aiohttp.ClientSession(loop=self.loop)
self.db = await asyncpg.create_pool(dsn=self.config['db'])
await self.login(self.config['token'])
await self.setup()
await self.connect()
async def get_context(self, message, *, cls=None):
return await super().get_context(message, cls=CTX)
Alfred().run()