Adapt to yaboli changes

The bot can now respond to alternate nicks.
This commit is contained in:
Joscha 2018-08-04 11:07:01 +00:00
parent a4f9142504
commit 4083b55d12

View file

@ -1,10 +1,12 @@
import asyncio import asyncio
import configparser import configparser
import logging import logging
import re
import yaboli import yaboli
from yaboli.utils import * from yaboli.utils import *
# Turn all debugging on # Turn all debugging on
asyncio.get_event_loop().set_debug(True) asyncio.get_event_loop().set_debug(True)
#logging.getLogger("asyncio").setLevel(logging.INFO) #logging.getLogger("asyncio").setLevel(logging.INFO)
@ -17,27 +19,36 @@ class InfoBot(yaboli.Bot):
Display information about the clients connected to a room in its nick. Display information about the clients connected to a room in its nick.
""" """
async def on_send(self, room, message): async def on_command_specific(self, room, message, command, nick, argstr):
await self.botrulez_ping_general(room, message) is_mentioned = similar(nick, room.session.nick) or similar(nick, "infobot")
await self.botrulez_ping_specific(room, message) is_mentioned = is_mentioned or re.fullmatch("p?bl?n?|\(p?bl?n?\)", normalize(nick))
await self.botrulez_help_general(room, message, text="I count the types of clients in my nick") if is_mentioned:
await self.botrulez_uptime(room, message) if not argstr:
await self.botrulez_kill(room, message) await self.botrulez_ping(room, message, command)
await self.botrulez_restart(room, message) await self.botrulez_uptime(room, message, command)
await self.botrulez_kill(room, message, command)
await self.botrulez_restart(room, message, command)
await self.command_help(room, message) await self.command_recount(room, message, command)
await self.command_recount(room, message) await self.command_detail(room, message, command)
await self.command_detail(room, message)
await self.command_hosts(room, message)
@yaboli.command("help", specific=True, args=True) await self.command_help(room, message, command, argstr)
await self.command_hosts(room, message, command, argstr)
async def on_command_general(self, room, mesage, command, argstr):
if not argstr:
await self.botrulez_ping(room, message, command)
await self.botrulez_help(room, message, command, text="I count the types of clients in my nick")
@yaboli.command("help")
async def command_help(self, room, message, argstr): async def command_help(self, room, message, argstr):
nick = mention(room.session.nick) nick = mention(room.session.nick)
args = self.parse_args(argstr) args = self.parse_args(argstr)
if not args: if not args:
text = ( text = (
"Displays information about the clients in a room in its nick:\n" "Displays information about the clients in a room in its nick:"
"(<people>P <bots>B <lurkers>L <bot-lurkers>N)\n" " (<people>P\u00A0<bots>B\u00A0<lurkers>L\u00A0<bot-lurkers>N)\n"
"You can also use @InfoBot, @PBL or @(PBL) for bot commands.\n"
"\n" "\n"
"!recount {nick} - Recount people in the room\n" "!recount {nick} - Recount people in the room\n"
"!detail {nick} - Detailed list of clients in this room\n" "!detail {nick} - Detailed list of clients in this room\n"
@ -116,13 +127,13 @@ class InfoBot(yaboli.Bot):
await room.who() await room.who()
await self.update_nick(room) await self.update_nick(room)
@yaboli.command("recount", specific=True, args=False) @yaboli.command("recount")
async def command_recount(self, room, message): async def command_recount(self, room, message):
await room.who() await room.who()
await self.update_nick(room) await self.update_nick(room)
await room.send("Recalibrated.", message.mid) await room.send("Recalibrated.", message.mid)
@yaboli.command("detail", specific=True, args=False) @yaboli.command("detail")
async def command_detail(self, room, message): async def command_detail(self, room, message):
sessions = room.listing.get() sessions = room.listing.get()
sessions = sorted(sessions, key=lambda s: s.uid) sessions = sorted(sessions, key=lambda s: s.uid)
@ -136,7 +147,7 @@ class InfoBot(yaboli.Bot):
is_manager = "yes" if s.is_manager else "no" 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}" 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", specific=True, args=True) @yaboli.command("hosts")
async def command_hosts(self, room, message, argstr): async def command_hosts(self, room, message, argstr):
flags, args, kwargs = self.parse_flags(self.parse_args(argstr)) flags, args, kwargs = self.parse_flags(self.parse_args(argstr))
sessions = room.listing.get() sessions = room.listing.get()
@ -154,7 +165,6 @@ def main(configfile):
nick = config.get("general", "nick") nick = config.get("general", "nick")
cookiefile = config.get("general", "cookiefile", fallback=None) cookiefile = config.get("general", "cookiefile", fallback=None)
print(cookiefile)
bot = InfoBot(nick, cookiefile=cookiefile) bot = InfoBot(nick, cookiefile=cookiefile)
for room, password in config.items("rooms"): for room, password in config.items("rooms"):