feat(bot): add subscribe/unsubscribe commands and bot bootstrap
This commit is contained in:
parent
f1bf86a5c9
commit
b9c0eda8b5
3 changed files with 72 additions and 0 deletions
6
bot/Dockerfile
Normal file
6
bot/Dockerfile
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY chorus_bot ./chorus_bot
|
||||
CMD ["python", "-m", "chorus_bot.main"]
|
||||
29
bot/chorus_bot/cogs/subscribe.py
Normal file
29
bot/chorus_bot/cogs/subscribe.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class SubscribeCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot, config):
|
||||
self.bot = bot
|
||||
self.config = config
|
||||
|
||||
@app_commands.command(name="subscribe", description="Get pinged when new items land in #inbox")
|
||||
async def subscribe(self, interaction: discord.Interaction):
|
||||
role = interaction.guild.get_role(self.config.triage_role_id)
|
||||
await interaction.user.add_roles(role)
|
||||
await interaction.response.send_message(
|
||||
"You're subscribed to Chorus inbox pings.", ephemeral=True
|
||||
)
|
||||
|
||||
@app_commands.command(name="unsubscribe", description="Stop getting pinged for new items")
|
||||
async def unsubscribe(self, interaction: discord.Interaction):
|
||||
role = interaction.guild.get_role(self.config.triage_role_id)
|
||||
await interaction.user.remove_roles(role)
|
||||
await interaction.response.send_message(
|
||||
"You're unsubscribed from Chorus inbox pings.", ephemeral=True
|
||||
)
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot, config):
|
||||
await bot.add_cog(SubscribeCog(bot, config))
|
||||
37
bot/chorus_bot/main.py
Normal file
37
bot/chorus_bot/main.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from chorus_bot.config import load_config
|
||||
from chorus_bot.backend_client import BackendClient
|
||||
from chorus_bot.cogs.manual_share import setup as setup_manual_share
|
||||
from chorus_bot.cogs.email_ingest import setup as setup_email_ingest
|
||||
from chorus_bot.cogs.thread_ingest import setup as setup_thread_ingest
|
||||
from chorus_bot.cogs.subscribe import setup as setup_subscribe
|
||||
|
||||
|
||||
def build_bot() -> commands.Bot:
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
return commands.Bot(command_prefix="!", intents=intents)
|
||||
|
||||
|
||||
async def main():
|
||||
config = load_config()
|
||||
bot = build_bot()
|
||||
backend_client = BackendClient(config.backend_base_url)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
await setup_manual_share(bot, config)
|
||||
await setup_email_ingest(bot, config)
|
||||
await setup_thread_ingest(bot, config, backend_client)
|
||||
await setup_subscribe(bot, config)
|
||||
await bot.tree.sync(guild=discord.Object(id=config.guild_id))
|
||||
print(f"Chorus bot ready as {bot.user}")
|
||||
|
||||
await bot.start(config.discord_token)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Loading…
Reference in a new issue