-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
114 lines (92 loc) · 2.59 KB
/
main.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
import logging
import os
import sqlite3
import disnake
from disnake import Intents
from disnake.ext import commands
logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(name)s: [%(levelname)s] - %(message)s"
)
class Bot(commands.Bot):
def __init__(self):
intents = Intents.default()
intents.message_content = True
intents.members = True
intents.presences = False
intents.typing = False
super().__init__(
command_prefix="&",
intents=intents,
)
self.logger = logging.getLogger("Bot")
self.token = os.getenv("BOT_TOKEN")
self.conn = sqlite3.connect("database.db")
self.cursor = self.conn.cursor()
self.setup_db()
self.load_extensions("cogs")
def setup_db(self):
self.cursor.execute(
"""
CREATE TABLE IF NOT EXISTS version_info (
id INTEGER PRIMARY KEY AUTOINCREMENT,
major INTEGER,
minor INTEGER,
patch INTEGER
)
"""
)
self.cursor.execute(
"""
SELECT 1 FROM version_info
"""
)
if self.cursor.fetchone() is None:
self.cursor.execute(
"""
INSERT INTO version_info (major, minor, patch)
VALUES (0, 0, 0)
"""
)
self.cursor.execute(
"""
CREATE TABLE IF NOT EXISTS crashes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
short_name TEXT,
message TEXT,
response TEXT,
times_used INTEGER
)
"""
)
self.conn.commit()
def run(self):
super().run(self.token)
async def close(self):
await super().close()
self.conn.close()
bot = Bot()
@bot.check
async def check(ctx: commands.Context):
roles_to_check = {
123,
456,
789,
}
if not ctx.guild:
raise commands.NoPrivateMessage
if roles_to_check & {role.id for role in ctx.author.roles}:
return True
raise commands.MissingRole("Error")
@bot.slash_command_check
async def check_slash(inter: disnake.AppCommandInteraction):
roles_to_check = {
123,
456,
789,
}
if not inter.guild:
raise commands.NoPrivateMessage
if roles_to_check & {role.id for role in inter.author.roles}:
return True
raise commands.MissingRole
bot.run()