mirror of
https://github.com/TehPeGaSuS/GitBot.git
synced 2026-06-27 17:45:44 +02:00
Add join/part command to the bot
This commit is contained in:
@@ -134,7 +134,8 @@ class Bot:
|
||||
|
||||
await commands.handle_pm(
|
||||
network, nick, prefix, text,
|
||||
self._database, pm_reply, self.reload)
|
||||
self._database, pm_reply, self.reload,
|
||||
self.join_channel, self.part_channel)
|
||||
elif target.startswith("#"):
|
||||
# Channel message
|
||||
async def ch_reply(msg):
|
||||
@@ -142,13 +143,39 @@ class Bot:
|
||||
|
||||
await commands.handle_channel(
|
||||
network, target, nick, prefix, text,
|
||||
self._database, ch_reply, self.reload)
|
||||
self._database, ch_reply, self.reload,
|
||||
self.join_channel, self.part_channel)
|
||||
|
||||
async def _on_connected(self, network: str):
|
||||
log.info("[%s] Connected and registered", network)
|
||||
|
||||
# ── Hot reload ────────────────────────────────────────────────────────────
|
||||
|
||||
async def join_channel(self, network: str, channel: str) -> str:
|
||||
"""Join a channel on a network. Called from IRC commands."""
|
||||
client = self._clients.get(network)
|
||||
if not client:
|
||||
nets = ", ".join(self._clients) or "none"
|
||||
return f"Unknown network '{network}'. Connected networks: {nets}"
|
||||
if client.in_channel(channel):
|
||||
return f"Already in {channel} on {network}."
|
||||
client.join(channel)
|
||||
log.info("Joining %s on %s (via command)", channel, network)
|
||||
return f"Joining {channel} on {network}."
|
||||
|
||||
async def part_channel(self, network: str, channel: str) -> str:
|
||||
"""Part a channel on a network. Called from IRC commands."""
|
||||
client = self._clients.get(network)
|
||||
if not client:
|
||||
nets = ", ".join(self._clients) or "none"
|
||||
return f"Unknown network '{network}'. Connected networks: {nets}"
|
||||
if not client.in_channel(channel):
|
||||
return f"Not in {channel} on {network}."
|
||||
client.send(f"PART {channel} :Leaving")
|
||||
db.purge_channel(self._database, network, channel)
|
||||
log.info("Parting %s on %s (via command)", channel, network)
|
||||
return f"Left {channel} on {network}."
|
||||
|
||||
async def reload(self) -> str:
|
||||
"""
|
||||
Re-read the config file and reconcile network connections:
|
||||
|
||||
+60
-6
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user