Move channel list into ArkhamDBUpdater class
This commit is contained in:
parent
fb0a4cec6c
commit
480d234c0c
19
ahtcg_bot.py
19
ahtcg_bot.py
@ -11,17 +11,16 @@ from arkhamdb import ArkhamDBClient
|
|||||||
from secret import TOKEN
|
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):
|
class ArkhamDBUpdater(commands.Bot):
|
||||||
|
channel_list: set[int]
|
||||||
arkhamdb_client: ArkhamDBClient
|
arkhamdb_client: ArkhamDBClient
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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.arkhamdb_client = ArkhamDBClient()
|
||||||
self.setup_commands()
|
self.setup_commands()
|
||||||
@ -31,9 +30,9 @@ class ArkhamDBUpdater(commands.Bot):
|
|||||||
async def monitor(ctx: commands.Context):
|
async def monitor(ctx: commands.Context):
|
||||||
"""Watch this channel for deck links and link to latest versions."""
|
"""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)
|
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:
|
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):
|
async def on_ready(self):
|
||||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
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:
|
if message.author.id == self.user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.channel.id in channel_list:
|
if message.channel.id in self.channel_list:
|
||||||
await self.update_channel_latest_decks(message.channel)
|
await self.update_channel_latest_decks(message.channel)
|
||||||
|
|
||||||
async def on_message_edit(self, before: discord.Message, after: discord.Message):
|
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:
|
if after.author.id == self.user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
if after.channel.id in channel_list:
|
if after.channel.id in self.channel_list:
|
||||||
await self.update_channel_latest_decks(after.channel)
|
await self.update_channel_latest_decks(after.channel)
|
||||||
|
|
||||||
@tasks.loop(seconds=20)
|
@tasks.loop(seconds=20)
|
||||||
async def arkhamdb_monitor(self) -> None:
|
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)
|
channel = self.get_channel(channel_id)
|
||||||
await self.update_channel_latest_decks(channel)
|
await self.update_channel_latest_decks(channel)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user