forked from vutfitdiscord/rubbergod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubbergod.py
executable file
·127 lines (103 loc) · 3.59 KB
/
rubbergod.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
122
123
124
125
126
127
import argparse
import logging
import disnake
from disnake import AllowedMentions, Intents, TextChannel
from disnake.ext import commands
import database.db_migrations as migrations
from buttons.contestvote import ContestView
from buttons.poll import (PollBasicView, PollBooleanView, PollCloseView,
PollOpinionView, PollVotersView)
from buttons.report import (ReportAnonymView, ReportAnswerOnlyView,
ReportGeneralView, ReportMessageView)
from config.app_config import config
from config.messages import Messages
from features import presence
from features.error import ErrorLogger
logger = logging.getLogger('disnake')
logger.setLevel(logging.WARNING)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
parser = argparse.ArgumentParser()
parser.add_argument('--load_dump', type=str,
help='Imports SQL dump from SQL file to database.',
metavar='filepath.sql')
parser.add_argument('--load_subjects', action='store_true',
help='Fills DB with subjects.')
parser.add_argument('--init_db', action='store_true',
help='Creates missing DB tables without start bot.')
args = parser.parse_args()
if args.load_dump is not None:
migrations.load_dump(args.load_dump)
exit(0)
elif args.load_subjects:
migrations.load_subjects()
exit(0)
elif args.init_db:
migrations.init_db()
print("Init complete")
exit(0)
is_initialized = False
intents = Intents.none()
intents.guilds = True
intents.members = True
intents.emojis = True
intents.messages = True
intents.message_content = True
intents.reactions = True
intents.presences = True
intents.moderation = True
command_sync_flags = commands.CommandSyncFlags()
command_sync_flags.sync_commands_debug = False
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(*config.command_prefix),
help_command=None,
case_insensitive=True,
allowed_mentions=AllowedMentions(roles=False, everyone=False, users=True),
intents=intents,
command_sync_flags=command_sync_flags
)
presence = presence.Presence(bot)
err_logger = ErrorLogger(bot)
@bot.event
async def on_ready():
"""If RubberGod is ready"""
# Inspired from https://github.com/sinus-x/rubbergoddess/blob/master/rubbergoddess.py
global is_initialized
if is_initialized:
return
is_initialized = True
views = [
ReportGeneralView(bot),
ReportMessageView(bot),
ReportAnonymView(bot),
ReportAnswerOnlyView(bot),
PollBasicView(bot),
PollBooleanView(bot),
PollOpinionView(bot),
PollCloseView(bot),
PollVotersView(bot),
ContestView(bot)
]
for view in views:
bot.add_view(view)
bot_room: TextChannel = bot.get_channel(config.bot_room)
if bot_room is not None:
await bot_room.send(Messages.on_ready_message)
await presence.set_presence()
print("Ready")
@bot.event
async def on_button_click(inter: disnake.MessageInteraction):
if inter.component.custom_id in ["trash:delete", "bookmark:delete"]:
await inter.message.delete()
@bot.event
async def on_error(event, *args, **kwargs):
return await err_logger.handle_event_error(event, args)
# Create missing tables at start
migrations.init_db()
bot.load_extension("cogs.system")
print("System cog loaded")
for extension in config.extensions:
bot.load_extension(f"cogs.{extension}")
print(f"{extension} loaded")
bot.run(config.key)