bitbot-3.11-fork/migration/v01.16.00-aliases.py

33 lines
1,012 B
Python
Raw Permalink Normal View History

2019-11-20 11:53:35 +00:00
# Used to migrate aliases from prior to v1.16.0
# usage: $ python3 migration/v01.16.00-aliases.py ~/.bitbot/bot.db
import argparse
parser = argparse.ArgumentParser(description="Migrate pre-v1.16.0 aliases")
parser.add_argument("database")
args = parser.parse_args()
import json, sqlite3
database = sqlite3.connect(args.database)
cursor = database.cursor()
cursor.execute(
"""SELECT server_id, value FROM server_settings
WHERE setting='command-aliases'""")
results = cursor.fetchall()
cursor.execute("SELECT server_id, alias FROM servers")
servers = dict(cursor.fetchall())
2019-11-20 11:53:35 +00:00
for server_id, value in results:
aliases = json.loads(value)
for alias, command in aliases.items():
print("[%s] Migrating '%s' ('%s')" %
(servers[server_id], alias, command))
2019-11-20 11:53:35 +00:00
cursor.execute("INSERT INTO server_settings VALUES (?, ?, ?)",
2019-11-20 12:41:31 +00:00
[server_id, "command-alias-%s" % alias, json.dumps(command)])
2019-11-20 11:53:35 +00:00
database.commit()
database.close()
2019-11-20 11:59:23 +00:00
print()
print("Migration successful!")