added first slashcommand and refactored the preview cog as result of breaking changes in slashcommand
This commit is contained in:
34
jeevesbot/database.py
Normal file
34
jeevesbot/database.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sqlite3
|
||||
|
||||
def init_db():
|
||||
conn = sqlite3.connect(r"jeevesbot/databases/reminders.db")
|
||||
c = conn.cursor()
|
||||
c.execute('''
|
||||
CREATE TABLE IF NOT EXISTS reminders (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER,
|
||||
message TEXT,
|
||||
reminder_time TIMESTAMP
|
||||
)
|
||||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def add_reminder(user_id, message, reminder_time):
|
||||
conn = sqlite3.connect(r"jeevesbot/databases/reminders.db")
|
||||
c = conn.cursor()
|
||||
c.execute('INSERT INTO reminders (user_id, message, reminder_time) VALUES (?, ?, ?)', (user_id, message, reminder_time))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_due_reminders(current_time):
|
||||
conn = sqlite3.connect(r"jeevesbot/databases/reminders.db")
|
||||
c = conn.cursor()
|
||||
c.execute('SELECT id, user_id, message FROM reminders WHERE reminder_time <= ?', (current_time,))
|
||||
reminders = c.fetchall()
|
||||
c.execute('DELETE FROM reminders WHERE reminder_time <= ?', (current_time,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return reminders
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
TOKEN = 'discord-bot-token-here'
|
||||
ADMIN_ROLE = 'role-to-exclude-from-gifbot'
|
||||
PREVIEWCHANNELS = [add-channel-ids-for-bot-to-work-in]
|
||||
GUILD_ID = 'id-of-guild'
|
||||
PREVIEWCHANNELS = ['add-channel-ids-for-bot-to-work-in']
|
||||
@@ -17,16 +17,3 @@ def roll(notation):
|
||||
result = int(roll)
|
||||
return roll,result
|
||||
|
||||
# check if user has admin role and output True if it's the case.
|
||||
def checkrole(roles):
|
||||
for role in roles:
|
||||
if str(role) == env.ADMIN_ROLE:
|
||||
return True
|
||||
|
||||
# check if the source channel is in the list of channels that are watched by the bot.
|
||||
def checkchannel(channelid):
|
||||
if channelid in env.PREVIEWCHANNELS:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user