Implement !kill

This commit is contained in:
Joscha 2019-04-12 12:08:26 +00:00
parent a0f7c8e84a
commit 3255ea770e
3 changed files with 18 additions and 4 deletions

View file

@ -49,7 +49,6 @@ i. e. the text between the end of the "!echo" and the end of the whole message.
## TODOs ## TODOs
- [ ] implement !kill
- [ ] implement !restart and add an easier way to run bots - [ ] implement !restart and add an easier way to run bots
- [ ] untruncate LiveMessage-s - [ ] untruncate LiveMessage-s
- [ ] config file support for bots, used by default - [ ] 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 project readme
- [ ] write examples - [ ] write examples
- [x] implement !uptime for proper botrulez conformity - [x] implement !uptime for proper botrulez conformity
- [x] implement !kill

View file

@ -16,6 +16,7 @@ class Bot(Client):
PING_REPLY: str = "Pong!" PING_REPLY: str = "Pong!"
HELP_GENERAL: Optional[str] = None HELP_GENERAL: Optional[str] = None
HELP_SPECIFIC: Optional[List[str]] = None HELP_SPECIFIC: Optional[List[str]] = None
KILL_REPLY: str = "/me dies"
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
@ -79,7 +80,8 @@ class Bot(Client):
def register_botrulez(self, def register_botrulez(self,
ping: bool = True, ping: bool = True,
help_: bool = True, help_: bool = True,
uptime: bool = True uptime: bool = True,
kill: bool = False,
) -> None: ) -> None:
if ping: if ping:
self.register_general("ping", self.cmd_ping, args=False) self.register_general("ping", self.cmd_ping, args=False)
@ -95,6 +97,9 @@ class Bot(Client):
if uptime: if uptime:
self.register_specific("uptime", self.cmd_uptime, args=False) 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, async def cmd_ping(self,
room: Room, room: Room,
message: LiveMessage, message: LiveMessage,
@ -127,3 +132,11 @@ class Bot(Client):
delta = format_delta(datetime.datetime.now() - self.start_time) delta = format_delta(datetime.datetime.now() - self.start_time)
text = f"/me has been up since {time} UTC ({delta})" text = f"/me has been up since {time} UTC ({delta})"
await message.reply(text) 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)

View file

@ -438,10 +438,11 @@ class Connection:
# to http://api.euphoria.io/#packets. # to http://api.euphoria.io/#packets.
# First, notify whoever's waiting for this packet # 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: 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: if future is not None:
del self._awaiting_replies[packet_id]
future.set_result(packet) future.set_result(packet)
# Then, send the corresponding event # Then, send the corresponding event