Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/bub/channels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def needs_debounce(self) -> bool:
"""Whether this channel needs debounce to prevent overload. Default to False."""
return False

@property
def enabled(self) -> bool:
"""Whether this channel is enabled. Default to True."""
return True

async def send(self, message: ChannelMessage) -> None:
"""Send a message to the channel. Optional to implement."""
# Do nothing by default
Expand Down
6 changes: 4 additions & 2 deletions src/bub/channels/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ async def quit(self, session_id: str) -> None:
def enabled_channels(self) -> list[Channel]:
if "all" in self._enabled_channels:
# Exclude 'cli' channel from 'all' to prevent interference with other channels
return [channel for name, channel in self._channels.items() if name != "cli"]
return [channel for name, channel in self._channels.items() if name in self._enabled_channels]
return [channel for name, channel in self._channels.items() if name != "cli" and channel.enabled]
return [
channel for name, channel in self._channels.items() if name in self._enabled_channels and channel.enabled
]

def _on_task_done(self, session_id: str, task: asyncio.Task) -> None:
task.exception() # to log any exception
Expand Down
4 changes: 4 additions & 0 deletions src/bub/channels/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def __init__(self, on_receive: MessageHandler) -> None:
self._parser = TelegramMessageParser(bot_getter=lambda: self._app.bot)
self._typing_tasks: dict[str, asyncio.Task] = {}

@property
def enabled(self) -> bool:
return bool(self._settings.token)

@property
def needs_debounce(self) -> bool:
return True
Expand Down
4 changes: 4 additions & 0 deletions tests/test_builtin_hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class DummyTelegramChannel:
def __init__(self, on_receive) -> None:
self.on_receive = on_receive

@property
def enabled(self) -> bool:
return True

import bub.channels.cli
import bub.channels.telegram

Expand Down
4 changes: 4 additions & 0 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ async def start(self, stop_event: asyncio.Event) -> None:
async def stop(self) -> None:
self.stopped = True

@property
def enabled(self) -> bool:
return True

async def send(self, message: ChannelMessage) -> None:
self.sent.append(message)

Expand Down
Loading