Merge branch 'main' of github.com:pvanarkel/discord-jeeves into main

This commit is contained in:
2025-03-30 20:51:19 +02:00
19 changed files with 221 additions and 287 deletions

View File

@@ -1,84 +0,0 @@
#!/usr/bin/env python3
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import random
from PIL import Image, ImageFont, ImageDraw
import textwrap
# setup gspread
scope = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('jeevesbot/secret.json', scope)
gclient = gspread.authorize(creds)
# load babbelbingofile
def babbelbingo_file():
file = gclient.open_by_key("1zdWl17fhdT2P96ZgjSwB_2wsCHi_ZVA42JroX5d1ylc")
babbelbingo = file.get_worksheet(1)
values = babbelbingo.get_all_values()
list_values = [item for sublist in values for item in sublist]
questions = random.sample(list_values, k=24)
return questions
def make_bingocard(name, questions):
image = Image.open('jeevesbot/files/bingokaart.png')
font_name = ImageFont.truetype('jeevesbot/files/Overpass-Regular.ttf', 13)
draw = ImageDraw.Draw(image)
wrapper = textwrap.TextWrapper(width=20, break_on_hyphens=True)
box01 = '\n'.join(wrapper.wrap(questions[0]))
box02 = '\n'.join(wrapper.wrap(questions[1]))
box03 = '\n'.join(wrapper.wrap(questions[2]))
box04 = '\n'.join(wrapper.wrap(questions[3]))
box05 = '\n'.join(wrapper.wrap(questions[4]))
box06 = '\n'.join(wrapper.wrap(questions[5]))
box07 = '\n'.join(wrapper.wrap(questions[6]))
box08 = '\n'.join(wrapper.wrap(questions[7]))
box09 = '\n'.join(wrapper.wrap(questions[8]))
box10 = '\n'.join(wrapper.wrap(questions[9]))
box11 = '\n'.join(wrapper.wrap(questions[10]))
box12 = '\n'.join(wrapper.wrap(questions[11]))
box13 = '\n'.join(wrapper.wrap(questions[12]))
box14 = '\n'.join(wrapper.wrap(questions[13]))
box15 = '\n'.join(wrapper.wrap(questions[14]))
box16 = '\n'.join(wrapper.wrap(questions[15]))
box17 = '\n'.join(wrapper.wrap(questions[16]))
box18 = '\n'.join(wrapper.wrap(questions[17]))
box19 = '\n'.join(wrapper.wrap(questions[18]))
box20 = '\n'.join(wrapper.wrap(questions[19]))
box21 = '\n'.join(wrapper.wrap(questions[20]))
box22 = '\n'.join(wrapper.wrap(questions[21]))
box23 = '\n'.join(wrapper.wrap(questions[22]))
box24 = '\n'.join(wrapper.wrap(questions[23]))
draw.multiline_text((95, 280.5), box01, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((229, 280.5), box02, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((363, 280.5), box03, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((497, 280.5), box04, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((631, 280.5), box05, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((95, 399.5), box06, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((229, 399.5), box07, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((363, 399.5), box08, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((497, 399.5), box09, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((631, 399.5), box10, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((95, 518.5), box11, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((229, 518.5), box12, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((497, 518.5), box13, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((631, 518.5), box14, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((95, 637.5), box15, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((229, 637.5), box16, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((363, 637.5), box17, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((497, 637.5), box18, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((631, 637.5), box19, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((95, 756.5), box20, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((229, 756.5), box21, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((363, 756.5), box22, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((497, 756.5), box23, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
draw.multiline_text((631, 756.5), box24, (0, 0, 0), font=font_name, align='center', anchor='mm', spacing=8)
table = str.maketrans({'(':None, ')':None, '/':None, ' ':'_'})
image.save('jeevesbot/files/generated_bingocards/' + str(name).translate(table) + '.png')
def bingo(name):
questions = babbelbingo_file()
make_bingocard(name, questions)
table = str.maketrans({'(':None, ')':None, '/':None, ' ':'_'})
bingoimage = ('jeevesbot/files/generated_bingocards/' + str(name).translate(table) + '.png')
return bingoimage

34
jeevesbot/database.py Normal file
View 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

View File

@@ -2,7 +2,5 @@
TOKEN = 'discord-bot-token-here'
ADMIN_ROLE = 'role-to-exclude-from-gifbot'
PREVIEWCHANNELS = [add-channel-ids-for-bot-to-work-in]
BOTCHANNEL = [add id of bot channel]
FLAIRROLES = [add list of role ids to correspond to the emoji]
FLAIRROLE = [add id of flair separator role]
GUILD_ID = 'id-of-guild'
PREVIEWCHANNELS = ['add-channel-ids-for-bot-to-work-in']

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -17,6 +17,7 @@ def roll(notation):
result = int(roll)
return roll,result
<<<<<<< HEAD
# check if user has admin role and output True if it's the case.
def checkrole(roles):
for role in roles:
@@ -30,3 +31,5 @@ def checkchannel(channelid):
else:
return False
=======
>>>>>>> d194332843b93f36e724aeca0dcd41c96a10ae95