fix(aurora): fixing sqlite queries and pylint errors
Some checks failed
Pylint / Pylint (3.11) (push) Failing after 43s
Some checks failed
Pylint / Pylint (3.11) (push) Failing after 43s
This commit is contained in:
parent
ca50deedd5
commit
a402f23001
3 changed files with 59 additions and 83 deletions
|
@ -10,7 +10,7 @@ from discord import Guild
|
|||
from redbot.core import data_manager
|
||||
|
||||
from .logger import logger
|
||||
from .utils import check_conf, generate_dict, get_next_case_number
|
||||
from .utils import generate_dict, get_next_case_number
|
||||
|
||||
|
||||
def connect() -> sqlite3.Connection:
|
||||
|
@ -37,43 +37,39 @@ async def create_guild_table(guild: Guild):
|
|||
except sqlite3.ProgrammingError:
|
||||
query = f"""
|
||||
CREATE TABLE `moderation_{guild.id}` (
|
||||
moderation_id INT UNIQUE PRIMARY KEY NOT NULL,
|
||||
timestamp INT NOT NULL,
|
||||
moderation_type LONGTEXT NOT NULL,
|
||||
target_type LONGTEXT NOT NULL,
|
||||
target_id LONGTEXT NOT NULL,
|
||||
moderator_id LONGTEXT NOT NULL,
|
||||
role_id LONGTEXT,
|
||||
duration LONGTEXT,
|
||||
end_timestamp INT,
|
||||
reason LONGTEXT,
|
||||
resolved BOOL NOT NULL,
|
||||
resolved_by LONGTEXT,
|
||||
resolve_reason LONGTEXT,
|
||||
expired BOOL NOT NULL,
|
||||
changes JSON NOT NULL,
|
||||
metadata JSON NOT NULL
|
||||
moderation_id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
moderation_type TEXT NOT NULL,
|
||||
target_type TEXT NOT NULL,
|
||||
target_id TEXT NOT NULL,
|
||||
moderator_id TEXT NOT NULL,
|
||||
role_id TEXT,
|
||||
duration TEXT,
|
||||
end_timestamp INTEGER,
|
||||
reason TEXT,
|
||||
resolved INTEGER NOT NULL,
|
||||
resolved_by TEXT,
|
||||
resolve_reason TEXT,
|
||||
expired INTEGER NOT NULL,
|
||||
changes TEXT NOT NULL,
|
||||
metadata TEXT NOT NULL
|
||||
)
|
||||
"""
|
||||
cursor.execute(query)
|
||||
|
||||
index_query_1 = "CREATE INDEX idx_target_id ON moderation_%s(target_id(25));"
|
||||
cursor.execute(index_query_1, (guild.id,))
|
||||
index_query_1 = "CREATE INDEX idx_target_id ON moderation_{}(target_id);"
|
||||
cursor.execute(index_query_1.format(guild.id))
|
||||
|
||||
index_query_2 = (
|
||||
"CREATE INDEX idx_moderator_id ON moderation_%s(moderator_id(25));"
|
||||
)
|
||||
cursor.execute(index_query_2, (guild.id,))
|
||||
index_query_2 = "CREATE INDEX idx_moderator_id ON moderation_{}(moderator_id);"
|
||||
cursor.execute(index_query_2.format(guild.id))
|
||||
|
||||
index_query_3 = (
|
||||
"CREATE INDEX idx_moderation_id ON moderation_%s(moderation_id);"
|
||||
)
|
||||
cursor.execute(index_query_3, (guild.id,))
|
||||
index_query_3 = "CREATE INDEX idx_moderation_id ON moderation_{}(moderation_id);"
|
||||
cursor.execute(index_query_3.format(guild.id))
|
||||
|
||||
insert_query = f"""
|
||||
INSERT INTO `moderation_{guild.id}`
|
||||
(moderation_id, timestamp, moderation_type, target_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
insert_values = (
|
||||
0,
|
||||
|
@ -98,7 +94,7 @@ async def create_guild_table(guild: Guild):
|
|||
database.commit()
|
||||
|
||||
logger.debug(
|
||||
"SQLite Table (moderation_%s) created for %s (%s)",
|
||||
"SQLite Table (moderation_?) created for ? (?)",
|
||||
guild.id,
|
||||
guild.name,
|
||||
guild.id,
|
||||
|
@ -122,9 +118,9 @@ async def mysql_log(
|
|||
resolved_by: str = None,
|
||||
resolved_reason: str = None,
|
||||
expired: bool = None,
|
||||
changes: list = [],
|
||||
metadata: dict = {},
|
||||
) -> int: # pylint: disable=dangerous-default-value
|
||||
changes: list = [], # pylint: disable=dangerous-default-value
|
||||
metadata: dict = {}, # pylint: disable=dangerous-default-value
|
||||
) -> int:
|
||||
if not timestamp:
|
||||
timestamp = int(time.time())
|
||||
|
||||
|
@ -155,7 +151,7 @@ async def mysql_log(
|
|||
|
||||
moderation_id = await get_next_case_number(guild_id=guild_id, cursor=cursor)
|
||||
|
||||
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
val = (
|
||||
moderation_id,
|
||||
timestamp,
|
||||
|
@ -210,8 +206,8 @@ async def fetch_case(moderation_id: int, guild_id: str) -> dict:
|
|||
database = connect()
|
||||
cursor = database.cursor()
|
||||
|
||||
query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;"
|
||||
cursor.execute(query, (guild_id, moderation_id))
|
||||
query = f"SELECT * FROM moderation_{guild_id} WHERE moderation_id = ?;"
|
||||
cursor.execute(query, (moderation_id,))
|
||||
result = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
|
|
|
@ -10,17 +10,6 @@ from redbot.core import commands
|
|||
from .config import config
|
||||
|
||||
|
||||
async def check_conf(config_list: list):
|
||||
"""Checks if any required config options are not set."""
|
||||
not_found_list = []
|
||||
|
||||
for item in config_list:
|
||||
if await config.item() == " ":
|
||||
not_found_list.append(item)
|
||||
|
||||
return not_found_list
|
||||
|
||||
|
||||
def check_permissions(
|
||||
user: User,
|
||||
permissions: list,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue