1b9aa47 · Slack and Discord adapters, dry-run first · 5 days ago

python27 lines · 878 B
1"""Discord adapter. Same wall, different transport."""
2
3from __future__ import annotations
4
5from typing import TextIO
6
7from mapping import Mapping
8from scope import ScopeGuard
9
10
11class DiscordAdapter:
12 def __init__(self, mapping: Mapping, guard: ScopeGuard) -> None:
13 self.mapping = mapping
14 self.guard = guard
15
16 def describe(self, out: TextIO) -> None:
17 m = self.mapping
18 out.write(f"axiom {m.agent} scope={m.scope} platform=discord\n")
19 for ch in m.channels:
20 out.write(f" {ch.role:12} {ch.direction:4} {ch.id} {ch.name}\n")
21 out.write("unknown channel ids are dropped before on_message\n")
22
23 def run(self, collect_seconds: int) -> None:
24 for ch in self.mapping.channels:
25 self.guard.require(ch.id, "listen")
26 raise SystemExit("live Discord requires DISCORD_BOT_TOKEN and discord.py")
27