Skip to content

Conversation

@Carlosdc25
Copy link

Adds a dedicated door webhook flow.

Adds DoorWebHookResponse base class & DoorToggled handler

@Carlosdc25 Carlosdc25 requested a review from cbrxyz January 30, 2026 16:47
Copy link
Member

@cbrxyz cbrxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Also, could you please add some instructions on how you tested the change?

src/env.py Outdated
Comment on lines 62 to 63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you made ensure_int, you might as well do:

Suggested change
GUILD_ID = ensure_int("GUILD_ID")
EMOJI_GUILD_ID = ensure_int("EMOJI_GUILD_ID")

Comment on lines +67 to +69
channel = self.bot.get_channel(LAB_DOOR_STATUS_CHANNEL_ID)
if channel is None:
channel = await self.bot.fetch_channel(LAB_DOOR_STATUS_CHANNEL_ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bot does not use explicit channel IDs for getting a discord.Channel resource because a channel ID refers to a specific channel in a specific guild. This means unless the bot instance running this code is in the specific guild in which this channel ID can be found, this code will not work.

Instead, create a class variable inside the bot class, and add your channel into RolesCog._load_channels(). No matter which server the bot is currently in (whether the MIL server, a test server, etc.), it should be able to load the correct channel.

discord-bot/src/roles.py

Lines 198 to 215 in 2370907

def _load_channels(self):
text_channels = {
"leave_channel": "leave-log",
"general_channel": "general",
"member_services_channel": "member-services",
"alumni_channel": "alumni",
"leaders_channel": "leads",
"operations_leaders_channel": "operations-leadership",
"software_leaders_channel": "software-leadership",
"electrical_leaders_channel": "electrical-leadership",
"mechanical_leaders_channel": "mechanical-leadership",
"message_log_channel": "message-log",
"errors_channel": "bot-errors",
"software_projects_channel": "software-projects",
}
for attr, name in text_channels.items():
setattr(self.bot, attr, self._get_text_channel(name))

Suggested change
channel = self.bot.get_channel(LAB_DOOR_STATUS_CHANNEL_ID)
if channel is None:
channel = await self.bot.fetch_channel(LAB_DOOR_STATUS_CHANNEL_ID)
channel = self.bot.lab_door_status_channel

src/webhooks.py Outdated
elif raw == "maybe":
text = "🤔-lab-maybe-open"
else:
text = f"Lab status: {raw}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Channel names are cut off after ~25 characters, meaning it could be hard to read whatever {raw} is here. I would throw an exception here, since this behavior is unexpected and you can be notified in #bot-log when the door sensor is returning an invalid value.

(unless you think it could be sending an invalid value regularly, in which case I would just combine this branch with the one before it to represent that the lab is possibly open)

src/webhooks.py Outdated


@dataclass
class DoorWebHookResponse:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class DoorWebHookResponse:
class DoorWebhookResponse:

src/webhooks.py Outdated
Comment on lines 46 to 50
async def ignore(self) -> bool:
if LAB_DOOR_STATUS_CHANNEL_ID is None:
logger.warning("LAB_DOOR_STATUS_CHANNEL_ID not set, skipping door update")
return True
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def ignore(self) -> bool:
if LAB_DOOR_STATUS_CHANNEL_ID is None:
logger.warning("LAB_DOOR_STATUS_CHANNEL_ID not set, skipping door update")
return True
return False

src/webhooks.py Outdated
Comment on lines 52 to 65
async def handle(self) -> None:
raw = str(self.payload.get("door_status", "")).strip().lower()
if not raw:
logger.warning("door_status missing in payload!")
return

if raw == "open":
text = "✅-lab-open"
elif raw == "closed":
text = "❌-lab-closed"
elif raw == "maybe":
text = "🤔-lab-maybe-open"
else:
text = f"Lab status: {raw}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def handle(self) -> None:
raw = str(self.payload.get("door_status", "")).strip().lower()
if not raw:
logger.warning("door_status missing in payload!")
return
if raw == "open":
text = "✅-lab-open"
elif raw == "closed":
text = "❌-lab-closed"
elif raw == "maybe":
text = "🤔-lab-maybe-open"
else:
text = f"Lab status: {raw}"
async def door_status(self) -> str | None:
return str(self.payload.get("door_status", "")).strip().lower() or None
async def handle(self) -> None:
door_status = await self.door_status()
if not door_status:
logger.warning("door_status missing in payload!")
return
channel_names = {
"open": "✅-lab-open",
"closed": "❌-lab-closed",
"maybe": "🤔-lab-maybe-open",
}
text = channel_names.get(door_status, "❓-lab-status-unknown")



@dataclass
class WebhookResponse:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class WebhookResponse:
class GitHubWebhookResponse:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants