mirror of
https://github.com/alterware/aw-bot.git
synced 2025-10-26 06:05:54 +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)
|
||||
|
||||
# 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(
|
||||
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)
|
||||
if spam_role:
|
||||
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):
|
||||
|
||||
@@ -59,28 +59,28 @@ def remove_pattern(pattern_id: int):
|
||||
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."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat()),
|
||||
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
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."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat()),
|
||||
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -7,5 +7,6 @@ CREATE TABLE IF NOT EXISTS message_patterns (
|
||||
CREATE TABLE IF NOT EXISTS user_roles (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
role_id INTEGER NOT NULL,
|
||||
date_assigned TEXT
|
||||
date_assigned TEXT,
|
||||
user_name TEXT
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user