-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
67 lines (46 loc) · 1.47 KB
/
core.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
# core.py
from os import getenv
from sys import modules
from time import time
from discord import Intents
from discord.app_commands import CommandTree, command
from discord.ext import commands
from dotenv import load_dotenv
import autoload
print('Hello world, core.py here!')
bot = commands.Bot(command_prefix='_', intents=Intents.all(), tree_cls=CommandTree)
class Exports:
def __init__(self):
self.internal = dict()
def put(self, key, value):
self.internal[key] = value
def put_if_none(self, key, value):
if self.get(key)() is None:
self.put(key, value)
def get(self, key):
return self.get_or_default(key, None)
def get_or_default(self, key, value):
if key not in self.internal.keys():
self.internal[key] = value
return lambda: self.internal[key]
def delete(self, key):
del self.internal[key]
exports = Exports()
channel_cache = dict()
async def channel_provider(channel_id):
channel = bot.get_channel(channel_id)
if channel:
return channel
elif channel_id in channel_cache.keys():
return channel_cache[channel_id]
else:
channel = await bot.fetch_channel(channel_id)
channel_cache[channel_id] = channel
return channel
if __name__ == '__main__':
load_dotenv()
autoload.load_initial(modules[__name__])
TOKEN = getenv('DISCORD_TOKEN')
print('Connecting to Discord...')
startTime = time()
bot.run(TOKEN)