Use command.Bot for better commands/automatic help
This commit is contained in:
parent
727476112e
commit
fb0a4cec6c
35
ahtcg_bot.py
35
ahtcg_bot.py
@ -5,7 +5,7 @@ import json
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
from arkhamdb import ArkhamDBClient
|
from arkhamdb import ArkhamDBClient
|
||||||
from secret import TOKEN
|
from secret import TOKEN
|
||||||
@ -16,17 +16,32 @@ with open('channel_list.json') as f:
|
|||||||
channel_list = json.load(f)
|
channel_list = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
class ArkhamDBUpdater(discord.Client):
|
class ArkhamDBUpdater(commands.Bot):
|
||||||
arkhamdb_client: ArkhamDBClient
|
arkhamdb_client: ArkhamDBClient
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
self.arkhamdb_client = ArkhamDBClient()
|
||||||
|
self.setup_commands()
|
||||||
|
|
||||||
|
def setup_commands(self):
|
||||||
|
@self.command(name='monitor')
|
||||||
|
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)
|
||||||
|
with open('channel_list.json', 'w') as f:
|
||||||
|
json.dump(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})')
|
||||||
print('Enabled on servers:')
|
print('Enabled on servers:')
|
||||||
async for guild in self.fetch_guilds(limit=150):
|
async for guild in self.fetch_guilds(limit=150):
|
||||||
print(' ', guild.name)
|
print(' -', guild.name)
|
||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
self.arkhamdb_client = ArkhamDBClient()
|
|
||||||
self.arkhamdb_monitor.start()
|
self.arkhamdb_monitor.start()
|
||||||
|
|
||||||
async def gather_deck_ids(self, channel: discord.TextChannel) -> dict[int, str]:
|
async def gather_deck_ids(self, channel: discord.TextChannel) -> dict[int, str]:
|
||||||
@ -74,16 +89,12 @@ class ArkhamDBUpdater(discord.Client):
|
|||||||
await channel.send(embed=message_embed)
|
await channel.send(embed=message_embed)
|
||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
|
await self.process_commands(message)
|
||||||
|
|
||||||
# we do not want the bot to reply to itself
|
# we do not want the bot to reply to itself
|
||||||
if message.author.id == self.user.id:
|
if message.author.id == self.user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.content.startswith('!arkhamdb_monitor'):
|
|
||||||
await message.reply('Hello!', mention_author=True)
|
|
||||||
channel_list.append(message.channel.id)
|
|
||||||
with open('channel_list.json', 'w') as f:
|
|
||||||
json.dump(channel_list, f)
|
|
||||||
|
|
||||||
if message.channel.id in channel_list:
|
if message.channel.id in channel_list:
|
||||||
await self.update_channel_latest_decks(message.channel)
|
await self.update_channel_latest_decks(message.channel)
|
||||||
|
|
||||||
@ -102,5 +113,5 @@ class ArkhamDBUpdater(discord.Client):
|
|||||||
await self.update_channel_latest_decks(channel)
|
await self.update_channel_latest_decks(channel)
|
||||||
|
|
||||||
|
|
||||||
client = ArkhamDBUpdater()
|
bot = ArkhamDBUpdater(command_prefix='!arkhamdb ')
|
||||||
client.run(TOKEN)
|
bot.run(TOKEN, reconnect=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user