-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
121 lines (100 loc) · 3.39 KB
/
run.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
114
115
116
117
118
119
120
121
#!/usr/bin/env python
# -*-coding=utf-8 -*-
import asyncio
import logging
import os
import subprocess
import sys
from typing import Optional
import disnake
from disnake.ext.commands import CommandSyncFlags
from bot.Not_a_bot import NotABot
from bot.config import Config, is_test_mode, get_test_guilds
from bot.formatter import LoggingFormatter
from utils import init_tf
test_mode = is_test_mode()
discord_logger = logging.getLogger('disnake')
discord_logger.setLevel(logging.DEBUG if test_mode else logging.INFO)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8-sig', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
discord_logger.addHandler(handler)
terminal = logging.getLogger('terminal')
terminal.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(LoggingFormatter('{color}[{module}][{asctime}] [Thread: {thread}] [{levelname}]:{colorend} {message}', datefmt='%Y-%m-%d %H:%M:%S', style='{'))
terminal.addHandler(handler)
error_handler = logging.FileHandler(filename='error.log', encoding='utf-8', mode='a')
error_handler.setFormatter(logging.Formatter('{color}[{module}][{asctime}] [Thread: {thread}] [{levelname}]:{colorend} {message}', datefmt='%Y-%m-%d %H:%M:%S', style='{'))
error_handler.setLevel(logging.ERROR)
terminal.addHandler(error_handler)
config = Config()
initial_cogs = [
'autoresponds',
'autoroles',
'botadmin',
'basic_logging',
'botmod',
'colors',
'command_blacklist',
'dbl',
'emotes',
'gachiGASM',
'images',
'jojo',
'last_seen',
'logging',
'misc',
'moderator',
'pokemon',
'privacy',
'search',
'server',
'server_specific',
'settings',
'stats',
'utils',
'voting']
initial_cogs = list(map('cogs.'.__add__, initial_cogs))
terminal.info('Main bot starting up')
# check whether convert is invoked with 'magick convert' or just convert
if not os.environ.get('MAGICK_PREFIX'):
try:
subprocess.call(['magick'], timeout=3, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
os.environ['MAGICK_PREFIX'] = 'magick '
except FileNotFoundError:
os.environ['MAGICK_PREFIX'] = ''
# Initialize tensorflow for text cmd
try:
model = init_tf.init_tf()
except ModuleNotFoundError:
model = None
except:
terminal.exception('Failed to initialize tensorflow')
model = None
intents = disnake.Intents.default()
intents.members = True
intents.message_content = True
intents.invites = False
intents.voice_states = False
bot: Optional[NotABot] = None
async def main():
global bot
if test_mode:
bot = NotABot(prefix='-', conf=config, max_messages=5000,
test_mode=True, cogs=initial_cogs, model=model,
intents=intents, test_guilds=get_test_guilds(),
command_sync_flags=CommandSyncFlags.all())
else:
bot = NotABot(prefix='!', conf=config, max_messages=5000,
cogs=initial_cogs,
model=model, shard_count=2, intents=intents,
chunk_guilds_at_startup=False)
await bot.async_init()
bot.load_default_cogs()
await bot.start(os.getenv('TOKEN'))
asyncio.run(main(), debug=test_mode)
# We have systemctl set up in a way that different exit codes
# have different effects on restarting behavior
import sys
if bot:
sys.exit(bot.exit_code)