Move channel list into ArkhamDBUpdater class

This commit is contained in:
Adam Goldsmith 2021-05-03 00:35:30 -04:00
parent fb0a4cec6c
commit 480d234c0c

View File

@ -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)