mirror of
https://github.com/alterware/aw-bot.git
synced 2025-11-18 09:02:07 +00:00
feat: migrate DB table
This commit is contained in:
@@ -293,7 +293,7 @@ async def handle_message(message, bot):
|
|||||||
await member.add_roles(spam_role)
|
await member.add_roles(spam_role)
|
||||||
|
|
||||||
# Add the user to the database
|
# Add the user to the database
|
||||||
add_user_to_role(member.id, SPAM_ROLE_ID)
|
add_user_to_role(member.id, SPAM_ROLE_ID, member.name)
|
||||||
|
|
||||||
await message.reply(
|
await message.reply(
|
||||||
f"Dink Donk! Time to ping everyone! {spam_role.mention}",
|
f"Dink Donk! Time to ping everyone! {spam_role.mention}",
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ async def migrate_all_users(bot):
|
|||||||
spam_role = discord.utils.get(guild.roles, id=SPAM_ROLE_ID)
|
spam_role = discord.utils.get(guild.roles, id=SPAM_ROLE_ID)
|
||||||
if spam_role:
|
if spam_role:
|
||||||
for member in spam_role.members:
|
for member in spam_role.members:
|
||||||
migrate_users_with_role(member.id, SPAM_ROLE_ID)
|
migrate_users_with_role(member.id, SPAM_ROLE_ID, member.name)
|
||||||
|
|
||||||
|
|
||||||
class SteamSaleChecker(commands.Cog):
|
class SteamSaleChecker(commands.Cog):
|
||||||
|
|||||||
@@ -59,28 +59,28 @@ def remove_pattern(pattern_id: int):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def migrate_users_with_role(user_id: int, role_id: int):
|
def migrate_users_with_role(user_id: int, role_id: int, user_name: str):
|
||||||
"""Migrates existing users with the role to the new table."""
|
"""Migrates existing users with the role to the new table."""
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||||
(user_id, role_id, aware_utcnow().isoformat()),
|
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def add_user_to_role(user_id: int, role_id: int):
|
def add_user_to_role(user_id: int, role_id: int, user_name: str):
|
||||||
"""Adds a new user when they receive the role."""
|
"""Adds a new user when they receive the role."""
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||||
(user_id, role_id, aware_utcnow().isoformat()),
|
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ CREATE TABLE IF NOT EXISTS message_patterns (
|
|||||||
CREATE TABLE IF NOT EXISTS user_roles (
|
CREATE TABLE IF NOT EXISTS user_roles (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY,
|
||||||
role_id INTEGER NOT NULL,
|
role_id INTEGER NOT NULL,
|
||||||
date_assigned TEXT
|
date_assigned TEXT,
|
||||||
|
user_name TEXT
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user