mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
🎨 chore(*): run black to format the code
This commit is contained in:
35
src/guild.py
35
src/guild.py
@@ -5,6 +5,7 @@ from src.utils.SqlConnector import sql
|
||||
from datetime import datetime
|
||||
from src.utils.variousclasses import models, characters
|
||||
|
||||
|
||||
class Guild:
|
||||
def __init__(self, id: int):
|
||||
self.id = id
|
||||
@@ -20,14 +21,18 @@ class Guild:
|
||||
self.updateDbData()
|
||||
with sql.mainDb as con:
|
||||
curs_data = con.cursor()
|
||||
curs_data.execute("SELECT * FROM setup_data WHERE guild_id = ?", (self.id,))
|
||||
curs_data.execute(
|
||||
"SELECT * FROM setup_data WHERE guild_id = ?", (self.id,)
|
||||
)
|
||||
data = curs_data.fetchone()
|
||||
data = orjson.loads(data[1])
|
||||
self.premium = data["premium"]
|
||||
self.channels = data["channels"]
|
||||
self.api_keys = data["api_keys"]
|
||||
if self.premium:
|
||||
self.premium_expiration = datetime.fromisoformat(data.get("premium_expiration", None))
|
||||
self.premium_expiration = datetime.fromisoformat(
|
||||
data.get("premium_expiration", None)
|
||||
)
|
||||
self.checkPremiumExpires()
|
||||
else:
|
||||
self.premium_expiration = None
|
||||
@@ -48,7 +53,9 @@ class Guild:
|
||||
"premium": self.premium,
|
||||
"channels": self.channels,
|
||||
"api_keys": self.api_keys,
|
||||
"premium_expiration": self.premium_expiration.isoformat() if self.premium else None,
|
||||
"premium_expiration": self.premium_expiration.isoformat()
|
||||
if self.premium
|
||||
else None,
|
||||
}
|
||||
else:
|
||||
data = {
|
||||
@@ -61,22 +68,30 @@ class Guild:
|
||||
with sql.mainDb as con:
|
||||
curs_data = con.cursor()
|
||||
if self.isInDb:
|
||||
curs_data.execute("UPDATE setup_data SET guild_settings = ? WHERE guild_id = ?", (orjson.dumps(data), self.id))
|
||||
curs_data.execute(
|
||||
"UPDATE setup_data SET guild_settings = ? WHERE guild_id = ?",
|
||||
(orjson.dumps(data), self.id),
|
||||
)
|
||||
else:
|
||||
curs_data.execute("INSERT INTO setup_data (guild_id, guild_settings) VALUES (?, ?)", (self.id, orjson.dumps(data)))
|
||||
curs_data.execute(
|
||||
"INSERT INTO setup_data (guild_id, guild_settings) VALUES (?, ?)",
|
||||
(self.id, orjson.dumps(data)),
|
||||
)
|
||||
self.isInDb = True
|
||||
|
||||
|
||||
def load(self):
|
||||
self.getDbData()
|
||||
|
||||
|
||||
def addChannel(self, channel: discord.TextChannel, model: str, character: str):
|
||||
print(f"Adding channel {channel.id} to guild {self.id} with model {model} and character {character}")
|
||||
print(
|
||||
f"Adding channel {channel.id} to guild {self.id} with model {model} and character {character}"
|
||||
)
|
||||
self.channels[str(channel.id)] = {
|
||||
"model": model,
|
||||
"character": character,
|
||||
}
|
||||
self.updateDbData()
|
||||
|
||||
|
||||
def delChannel(self, channel: discord.TextChannel):
|
||||
del self.channels[str(channel.id)]
|
||||
self.updateDbData()
|
||||
@@ -99,4 +114,4 @@ class Guild:
|
||||
|
||||
def addApiKey(self, api: str, key: str):
|
||||
self.api_keys[api] = key
|
||||
self.updateDbData()
|
||||
self.updateDbData()
|
||||
|
||||
Reference in New Issue
Block a user