Compare commits

..

No commits in common. "8d33c22f712293503dfcc988a9af3d77dd52ca27" and "a2909447080760f9a7f627ac236e690a3be15289" have entirely different histories.

6 changed files with 11 additions and 65 deletions

View file

@ -1,18 +0,0 @@
from interactions import Extension, slash_command, SlashContext
from util.db import get_connection
class CharacterQuizExtension(Extension):
@slash_command(name="kviz", description="Kvíz postav podle tvého anime listu")
async def start_quiz(self, ctx: SlashContext):
await ctx.defer()
c = get_connection(ctx.author_id)
print(c)
if not c:
await ctx.respond("Nemáš propojený anime list, použij příkaz `/link` k propojení!", ephemeral=True)
return
_, _, name, service = c
await ctx.respond(content="Ok", ephemeral=True)

View file

@ -1,22 +0,0 @@
from interactions import Extension, slash_command, SlashContext, slash_option, OptionType, SlashCommandChoice
from util.db import get_connection, add_user_connection
class LinkExtension(Extension):
@slash_command(name="link", description="Propojí tvůj účet s anime listem")
@slash_option(name="username", description="Uživatelské jméno", required=True, opt_type=OptionType.STRING)
@slash_option(name="service", description="Služba (Anilist, MyAnimeList atp.)", required=True,
opt_type=OptionType.STRING,
choices=[SlashCommandChoice(name="Anilist", value="anilist"), ])
async def link(self, ctx: SlashContext, username: str, service: str):
await ctx.defer()
if get_connection(ctx.author_id) is not None:
await ctx.respond(content="Tvůj účet je již propojen!", ephemeral=True)
return
r = add_user_connection(ctx.author_id, username, service)
if not r:
await ctx.respond(content="Nepodařilo se propojit tě.", ephemeral=True)
return
await ctx.respond(content="Tvůj účet byl úspěšně propojen.", ephemeral=True)
return

View file

@ -11,7 +11,7 @@ timeout = datetime.now()
class YuriExtension(Extension):
@slash_command(name="yuri", description="Pošle náhodný yuri obrázek z Gelbooru (NSFW pouze v NSFW kanálech)")
async def yuri(self, ctx: SlashContext):
async def test(self, ctx: SlashContext):
global timeout
await ctx.defer()
if datetime.now() < timeout:

View file

@ -44,6 +44,4 @@ async def on_message_create(event: MessageCreate):
return
bot.load_extension("commands.yuri")
bot.load_extension("commands.link")
bot.load_extension("commands.character_quiz")
bot.start(DISCORD_TOKEN)

View file

@ -2,6 +2,7 @@ import sqlite3
from sqlite3 import Error, Connection
from util.config import DB_PATH
from util.enums import AnimeListServices
def setup_database() -> bool:
@ -28,37 +29,17 @@ def setup_database() -> bool:
return True
def get_connection(uid: str) -> tuple | None:
conn = create_connection()
try:
c = conn.cursor()
c.execute(f"""SELECT * FROM connections WHERE uid='{uid}';""")
o = c.fetchall()
conn.close()
if len(o) == 0:
return None
return o[0]
except Error as e:
print("Error finding user connection:")
print(e)
return None
def add_user_connection(uid: str, listname: str, service: str) -> bool:
def add_user_connection(uid: str, listname: str, service: AnimeListServices) -> bool:
conn = create_connection()
if conn is None:
print("No connection")
return False
try:
c = conn.cursor()
c.execute(f"""INSERT INTO connections(uid,animelist,service) VALUES('{uid}','{listname}','{service}')""")
conn.commit()
c.execute(f"""INSERT INTO connections(uid,animelist,service) VALUES('{uid}','{listname}','{service.value}')""")
except Error as e:
print("Error while adding a new connection:")
print(e)
return False
conn.close()
return True
def create_connection() -> Connection | None:

7
util/enums.py Normal file
View file

@ -0,0 +1,7 @@
from enum import Enum
class AnimeListServices(Enum):
ANILIST = "anilist"
MYANIMELIST = "mal"
ANIMEPLANET = "apl"