From 480d234c0c42c0111e2108721ef1c980d53d1c5d Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 3 May 2021 00:35:30 -0400 Subject: [PATCH] Move channel list into ArkhamDBUpdater class --- ahtcg_bot.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ahtcg_bot.py b/ahtcg_bot.py index 902072c..362deb2 100755 --- a/ahtcg_bot.py +++ b/ahtcg_bot.py @@ -11,17 +11,16 @@ from arkhamdb import ArkhamDBClient from secret import TOKEN -# TODO: should really be a database -with open('channel_list.json') as f: - channel_list = json.load(f) - - class ArkhamDBUpdater(commands.Bot): + channel_list: set[int] arkhamdb_client: ArkhamDBClient def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # TODO: should really be a database + with open('channel_list.json') as f: + self.channel_list = set(json.load(f)) self.arkhamdb_client = ArkhamDBClient() self.setup_commands() @@ -31,9 +30,9 @@ class ArkhamDBUpdater(commands.Bot): async def monitor(ctx: commands.Context): """Watch this channel for deck links and link to latest versions.""" await ctx.message.reply('Now monitoring this channel for deck IDs', mention_author=True) - channel_list.append(ctx.message.channel.id) + self.channel_list.add(ctx.message.channel.id) with open('channel_list.json', 'w') as f: - json.dump(channel_list, f) + json.dump(list(self.channel_list), f) async def on_ready(self): print(f'Logged in as {self.user} (ID: {self.user.id})') @@ -95,7 +94,7 @@ class ArkhamDBUpdater(commands.Bot): if message.author.id == self.user.id: return - if message.channel.id in channel_list: + if message.channel.id in self.channel_list: await self.update_channel_latest_decks(message.channel) async def on_message_edit(self, before: discord.Message, after: discord.Message): @@ -103,12 +102,12 @@ class ArkhamDBUpdater(commands.Bot): if after.author.id == self.user.id: return - if after.channel.id in channel_list: + if after.channel.id in self.channel_list: await self.update_channel_latest_decks(after.channel) @tasks.loop(seconds=20) async def arkhamdb_monitor(self) -> None: - for channel_id in channel_list: + for channel_id in self.channel_list: channel = self.get_channel(channel_id) await self.update_channel_latest_decks(channel)