From 948f509999d7fc836650c348daec07d9e4950086 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 13 Apr 2019 22:34:26 +0000 Subject: [PATCH] Add !hosts command --- infobot.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/infobot.py b/infobot.py index 8fe1eb5..cf4efcd 100644 --- a/infobot.py +++ b/infobot.py @@ -1,6 +1,7 @@ import logging import yaboli +from yaboli.util import * class InfoBot(yaboli.Bot): @@ -19,7 +20,7 @@ class InfoBot(yaboli.Bot): "!recount {atmention} - Recount people in the room", #"!detail {atmention} - Detailed list of clients in this room", #"!detail {atmention} @person - Detailed info regarding @person", - #"!hosts {atmention} [--mention] - Lists all hosts currently in this room", + "!hosts [--ping] - Lists all hosts currently in this room", "", "Created by @Garmy using https://github.com/Garmelon/yaboli.", "For additional info, try \"!help {atmention} \". Topics:", @@ -48,6 +49,7 @@ class InfoBot(yaboli.Bot): ] HELP_CHANGELOG = [ + "(2019-04-13) re-add !hosts command", "(2019-04-12) update to yaboli rewrite 5", ] @@ -63,6 +65,7 @@ class InfoBot(yaboli.Bot): self.register_general("help", self.cmd_help_general, args=False) self.register_specific("help", self.cmd_help_specific) self.register_specific("recount", self.cmd_recount, args=False) + self.register_general("hosts", self.cmd_hosts) async def cmd_help_specific(self, room, message, args): if not args.has_args(): @@ -84,6 +87,26 @@ class InfoBot(yaboli.Bot): await self.update_nick(room) await message.reply("Recalibrated.") + async def cmd_hosts(self, room, message, args): + fancy = args.fancy() + ping = "mention" in fancy.optional or "ping" in fancy.optional + + hosts = sorted(set(user.nick for user in room.users if user.is_manager)) + + lines = [] + for host in hosts: + if ping: + lines.append(atmention(host)) + else: + lines.append(host) + + if lines: + lines = ["Hosts that are currently in this room:"] + lines + else: + lines = ["No hosts currently in this room."] + + await message.reply("\n".join(lines)) + # Updating the nick def format_nick(self, users): @@ -169,22 +192,6 @@ class InfoBot(yaboli.Bot): # is_manager = "yes" if s.is_manager else "no" # return f"UID: {s.uid}\t| SID: {s.sid}\t| staff: {is_staff}\t| host: {is_manager}\t| nick: {s.nick!r}" # -# @yaboli.command("hosts") -# async def command_hosts(self, room, message, argstr): -# flags, args, kwargs = self.parse_flags(self.parse_args(argstr)) -# sessions = room.listing.get() -# sessions = sorted(set(s.nick for s in sessions if s.is_manager)) -# -# if "ping" in kwargs: -# sessions = [mention(s) for s in sessions] -# else: -# sessions = [s for s in sessions] -# -# if sessions: -# text = "Hosts that are currently in this room:\n" + "\n".join(sessions) -# else: -# text = "No hosts currently in this room." -# await room.send(text, message.mid) if __name__ == "__main__": yaboli.enable_logging(level=logging.DEBUG)