Skip to content

Commit

Permalink
change how the guard works
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed May 23, 2023
1 parent 9a54811 commit cfc7de4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ The original, asynchronous bot installs and uses this codebase to run the same c
- Run `poetry run jgc` to start the bot.
- Press <kbd>Ctrl+C</kbd> to stop the bot.

By default, the bot responds only in the club Discord guild.
If you need to test it in a different guild, set the environment variable `GUILD_ID` to the ID of the guild.

## Deployment

The bot is deployed to [fly.io](https://fly.io/).
Expand Down
11 changes: 6 additions & 5 deletions juniorguru_chick/bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import asyncio
from datetime import datetime
import logging
Expand All @@ -9,7 +10,7 @@
DAYS = ["Pondělní", "Úterní", "Středeční",
"Čtvrteční", "Páteční", "Sobotní", "Nedělní"]

CLUB_GUILD_ID = 769966886598737931
GUILD_ID = int(os.getenv('GUILD_ID', '769966886598737931'))

WELCOME_ROLE_ID = 1062755787153358879

Expand All @@ -31,8 +32,8 @@ async def on_ready():

@bot.event
async def on_message(message: discord.Message) -> None:
if message.guild and message.guild.id != CLUB_GUILD_ID:
logger.error(f"Not a club message! Guild ID: #{message.guild.id}")
if message.guild and message.guild.id != GUILD_ID:
logger.error(f"Message not in an allowed guild! #{message.guild.id}")
return

logger.info("Processing message")
Expand All @@ -59,8 +60,8 @@ async def on_message(message: discord.Message) -> None:

@bot.event
async def on_thread_create(thread: discord.Thread) -> None:
if thread.guild.id != CLUB_GUILD_ID:
logger.error(f"Not a club thread! Guild ID: #{thread.guild.id}")
if thread.guild.id != GUILD_ID:
logger.error(f"Thread not in an allowed guild! Guild ID: #{thread.guild.id}")
return

if not thread.parent:
Expand Down

0 comments on commit cfc7de4

Please sign in to comment.