From 3255ea770e89ddacfe6a496a4e87add8a140e390 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 12 Apr 2019 12:08:26 +0000 Subject: [PATCH] Implement !kill --- README.md | 2 +- yaboli/bot.py | 15 ++++++++++++++- yaboli/connection.py | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4e53a3e..00dc19c 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ i. e. the text between the end of the "!echo" and the end of the whole message. ## TODOs -- [ ] implement !kill - [ ] implement !restart and add an easier way to run bots - [ ] untruncate LiveMessage-s - [ ] config file support for bots, used by default @@ -63,3 +62,4 @@ i. e. the text between the end of the "!echo" and the end of the whole message. - [ ] write project readme - [ ] write examples - [x] implement !uptime for proper botrulez conformity +- [x] implement !kill diff --git a/yaboli/bot.py b/yaboli/bot.py index cc6a74a..92e55ab 100644 --- a/yaboli/bot.py +++ b/yaboli/bot.py @@ -16,6 +16,7 @@ class Bot(Client): PING_REPLY: str = "Pong!" HELP_GENERAL: Optional[str] = None HELP_SPECIFIC: Optional[List[str]] = None + KILL_REPLY: str = "/me dies" def __init__(self) -> None: super().__init__() @@ -79,7 +80,8 @@ class Bot(Client): def register_botrulez(self, ping: bool = True, help_: bool = True, - uptime: bool = True + uptime: bool = True, + kill: bool = False, ) -> None: if ping: self.register_general("ping", self.cmd_ping, args=False) @@ -95,6 +97,9 @@ class Bot(Client): if uptime: self.register_specific("uptime", self.cmd_uptime, args=False) + if kill: + self.register_specific("kill", self.cmd_kill, args=False) + async def cmd_ping(self, room: Room, message: LiveMessage, @@ -127,3 +132,11 @@ class Bot(Client): delta = format_delta(datetime.datetime.now() - self.start_time) text = f"/me has been up since {time} UTC ({delta})" await message.reply(text) + + async def cmd_kill(self, + room: Room, + message: LiveMessage, + args: SpecificArgumentData + ) -> None: + await message.reply(self.KILL_REPLY) + await self.part(room) diff --git a/yaboli/connection.py b/yaboli/connection.py index aa8dd60..fbb354f 100644 --- a/yaboli/connection.py +++ b/yaboli/connection.py @@ -438,10 +438,11 @@ class Connection: # to http://api.euphoria.io/#packets. # First, notify whoever's waiting for this packet - packet_id = packet.get("id", None) + packet_id = packet.get("id") if packet_id is not None and self._awaiting_replies is not None: - future = self._awaiting_replies.get(packet_id, None) + future = self._awaiting_replies.get(packet_id) if future is not None: + del self._awaiting_replies[packet_id] future.set_result(packet) # Then, send the corresponding event