From ef20cc608fd567e06cd71a4d2ba4b057445c18ba Mon Sep 17 00:00:00 2001 From: eibex <40539455+eibex@users.noreply.github.com> Date: Tue, 2 Mar 2021 21:05:00 +0100 Subject: [PATCH] remove migration and related code (#64) --- bot.py | 20 +------ core/__init__.py | 2 - core/migration.py | 136 ---------------------------------------------- 3 files changed, 1 insertion(+), 157 deletions(-) delete mode 100644 core/migration.py diff --git a/bot.py b/bot.py index bfcfab24..3b23fc29 100644 --- a/bot.py +++ b/bot.py @@ -33,14 +33,11 @@ import discord from discord.ext import commands, tasks -from core import database, migration, activity, github, schema +from core import database, activity, github, schema directory = os.path.dirname(os.path.realpath(__file__)) -migrated = migration.migrate() -config_migrated = migration.migrateconfig() - with open(f"{directory}/.version") as f: __version__ = f.read().rstrip("\n").rstrip("\r") @@ -404,21 +401,6 @@ async def check_cleanup_queued_guilds(): @bot.event async def on_ready(): print("Reaction Light ready!") - if migrated: - await system_notification( - None, - "Your CSV files have been deleted and migrated to an SQLite" - " `reactionlight.db` file.", - ) - - if config_migrated: - await system_notification( - None, - "Your `config.ini` has been edited and your admin IDs are now stored in" - f" the database.\nYou can add or remove them with `{prefix}admin` and" - f" `{prefix}rm-admin`.", - ) - await database_updates() maintain_presence.start() cleandb.start() diff --git a/core/__init__.py b/core/__init__.py index ded021df..9da01d9e 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,6 +1,4 @@ -from .migration import * from .activity import * -from .migration import * from .database import * from .github import * from .schema import * diff --git a/core/migration.py b/core/migration.py deleted file mode 100644 index 0df0fad2..00000000 --- a/core/migration.py +++ /dev/null @@ -1,136 +0,0 @@ -""" -MIT License - -Copyright (c) 2019-2021 eibex - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" - - -import os -import csv -import configparser -from . import database - - -def migrate(): - directory = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - folder = f"{directory}/files" - files = os.listdir(folder) - if "id.csv" not in files: - return False - else: - for file in os.listdir(folder): - if ( - file.endswith(".csv") - and file != "activities.csv" - and file != "cache.csv" - and file != "id.csv" - ): - print(f"Migrating {file}") - filepath = os.path.join(folder, file) - with open(filepath, "r") as f: - reader = csv.reader(f, delimiter=",") - counter = 0 - reaction_role = {} - for row in reader: - if counter == 0: - # if first iteration - # get channel id at top of csv file - channel_id = row[0] - counter += 1 - else: - reaction = row[0] - role_id = row[1] - reaction_role[reaction] = int(role_id) - - with open(f"{folder}/cache.csv", "r") as f: - reader = csv.reader(f, delimiter=",") - for row in reader: - embed_id = row[1] - if embed_id == file.rstrip(".csv"): - # reverse lookup of message_id via CSV embed_id - message_id = int(row[0]) - break - - tracker = database.ReactionRoleCreationTracker( - guild=None, database=f"{folder}/reactionlight.db" - ) - - print(f"Getting target channel: {channel_id}") - tracker.target_channel = channel_id - - print(f"Getting reaction-roles:\n{reaction_role}") - tracker.combos = reaction_role - - print(f"Getting message: {message_id}") - tracker.message_id = message_id - - print("Committing to database") - tracker.commit() - - print(f"Removing: {file}") - os.remove(filepath) - print(f"Removed: {file}\n\n") - - print("Removing id.csv and cache.csv") - os.remove(f"{folder}/cache.csv") - os.remove(f"{folder}/id.csv") - - print("\nMigration completed.") - return True - - -def migrateconfig(): - directory = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - configfile = f"{directory}/config.ini" - config = configparser.ConfigParser() - config.read(configfile) - try: - config.get("server", "colour") - - except configparser.NoOptionError: - config["server"]["colour"] = "0xffff00" - with open(configfile, "w") as f: - config.write(f) - - print("Migrated bot colour to config.ini") - - try: - admins = [ - int(config.get("server_role", "admin_a")), - int(config.get("server_role", "admin_b")), - int(config.get("server_role", "admin_c")), - ] - for admin in admins: - if admin != 0: - database.add_admin(admin) - - print("\nAdmin migration completed.") - config.remove_option("server_role", "admin_a") - config.remove_option("server_role", "admin_b") - config.remove_option("server_role", "admin_c") - config.remove_section("server_role") - with open(configfile, "w") as f: - config.write(f) - - return True - - except configparser.NoSectionError: - return False