-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsunbot.py
59 lines (48 loc) · 1.78 KB
/
sunbot.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
import asyncio
import logging
import os
from typing import List
import discord
from dotenv import load_dotenv
# from autoreactor import AutoReactorClientMixin
from projectrenderer import ProjectRendererClientMixin
from sunvoxaudio import SunvoxAudioUploaderMixin
log = logging.getLogger(__name__)
class SunBotClient(
discord.Client,
# AutoReactorClientMixin,
ProjectRendererClientMixin,
SunvoxAudioUploaderMixin,
):
def __init__(self, guild_names: List[str], **kwargs):
super(SunBotClient, self).__init__(**kwargs)
self.guild_names = guild_names
for cls in self.__class__.__bases__:
if callable(getattr(cls, "__post_init__", None)):
cls.__post_init__(self)
async def on_ready(self):
for cls in self.__class__.__bases__:
if callable(getattr(cls, "__on_ready__", None)):
await cls.__on_ready__(self)
async def on_message(self, message: discord.Message):
guild: discord.Guild = message.guild
if message.author == self.user or guild.name not in self.guild_names:
return
for cls in self.__class__.__bases__:
if callable(getattr(cls, "__on_message__", None)):
await cls.__on_message__(self, message)
async def main():
load_dotenv("local.env")
log_level = os.getenv("LOG_LEVEL", "INFO")
logging.basicConfig(level=log_level)
bot_token = os.environ["BOT_TOKEN"]
guild_names = os.environ["GUILD_NAMES"].split(";")
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
intents.message_content = True
client = SunBotClient(guild_names=guild_names, intents=intents)
async with client:
await client.start(bot_token)
if __name__ == "__main__":
asyncio.run(main())