Port to newest yaboli version (rewrite-4)
This commit is contained in:
parent
c600990c3f
commit
32605f6f97
2 changed files with 134 additions and 69 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,2 +1,5 @@
|
||||||
|
**/__pycache__
|
||||||
yaboli
|
yaboli
|
||||||
__pycache__
|
websockets
|
||||||
|
join_rooms.py
|
||||||
|
*.cookie
|
||||||
|
|
|
||||||
176
infobot.py
176
infobot.py
|
|
@ -1,7 +1,10 @@
|
||||||
import sys
|
import asyncio
|
||||||
|
|
||||||
import yaboli
|
import yaboli
|
||||||
from yaboli.utils import *
|
from yaboli.utils import *
|
||||||
|
|
||||||
|
# List of rooms kept in separate file, which is .gitignore'd
|
||||||
|
import join_rooms
|
||||||
|
|
||||||
|
|
||||||
class InfoBot(yaboli.Bot):
|
class InfoBot(yaboli.Bot):
|
||||||
|
|
@ -9,49 +12,89 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
short_help_text = "I show the types of clients in my nick"
|
||||||
super().__init__("()")
|
help_text = (
|
||||||
|
"Displays information about the clients in a room in its nick:\n"
|
||||||
|
"(<people>P <bots>B <lurkers>L <bot-lurkers>N)\n\n"
|
||||||
|
"!recount @{nick} - Recount people in the room\n\n"
|
||||||
|
"Created by @Garmy using yaboli.\n"
|
||||||
|
"For additional info, try \"!help @{nick} <topic>\". Topics:\n"
|
||||||
|
"count, lurkers, changelog"
|
||||||
|
)
|
||||||
|
|
||||||
self.add_help("count", (
|
|
||||||
|
async def send(self, room, message):
|
||||||
|
await self.botrulez_ping_general(room, message)
|
||||||
|
await self.botrulez_ping_specific(room, message)
|
||||||
|
await self.botrulez_help_general(room, message, help_text="I count the types of clients in my nick")
|
||||||
|
await self.botrulez_uptime(room, message)
|
||||||
|
await self.botrulez_kill(room, message)
|
||||||
|
await self.botrulez_restart(room, message)
|
||||||
|
|
||||||
|
await self.command_help(room, message)
|
||||||
|
await self.command_recount(room, message)
|
||||||
|
await self.command_detail(room, message)
|
||||||
|
await self.command_hosts(room, message)
|
||||||
|
|
||||||
|
forward = send
|
||||||
|
|
||||||
|
@yaboli.command("help", specific=True)
|
||||||
|
async def command_help(self, room, message, argstr):
|
||||||
|
nick = mention(room.session.nick)
|
||||||
|
args = self.parse_args(argstr)
|
||||||
|
if not args:
|
||||||
|
text = (
|
||||||
|
"Displays information about the clients in a room in its nick:\n"
|
||||||
|
"(<people>P <bots>B <lurkers>L <bot-lurkers>N)\n"
|
||||||
|
"\n"
|
||||||
|
"!recount @{nick} - Recount people in the room\n"
|
||||||
|
"!detail @{nick} - Detailed list of clients in this room\n"
|
||||||
|
"!hosts @{nick} [--mention] - Lists all hosts currently in this room\n"
|
||||||
|
"\n"
|
||||||
|
"Created by @Garmy using https://github.com/Garmelon/yaboli.\n"
|
||||||
|
"For additional info, try \"!help @{nick} <topic>\". Topics:\n"
|
||||||
|
" count, lurkers, changelog"
|
||||||
|
).format(nick=nick)
|
||||||
|
await room.send(text, message.mid)
|
||||||
|
else:
|
||||||
|
for topic in args:
|
||||||
|
if topic == "count":
|
||||||
|
text = (
|
||||||
"This bot counts the number of clients connected to a room. If you"
|
"This bot counts the number of clients connected to a room. If you"
|
||||||
" open a room in two different tabs, the bot counts you twice.\n"
|
" open a room in two different tabs, the bot counts you twice.\n"
|
||||||
"The euphoria client, on the other hand, usually displays all"
|
"The euphoria client, on the other hand, usually displays all"
|
||||||
" connections of an account as one nick in the nick list. Because of"
|
" connections of an account as one nick in the nick list. Because of"
|
||||||
" that, this bot's count is always as high as, or higher than, the"
|
" that, this bot's count is always as high as, or higher than, the"
|
||||||
" number of nicks on the nick list, similar to the number on the"
|
" number of nicks on the nick list, similar to the number on the"
|
||||||
" button to toggle the nick list.\n\n"
|
" button to toggle the nick list.\n"
|
||||||
"If the bot's count is off, try a !recount."
|
"\n"
|
||||||
))
|
"If the bot's count is off, try a !recount or a !restart @{nick}."
|
||||||
|
).format(nick=nick)
|
||||||
self.add_help("lurkers", (
|
elif topic == "lurkers":
|
||||||
|
text = (
|
||||||
"People or bots who are connected to the room but haven't chosen a"
|
"People or bots who are connected to the room but haven't chosen a"
|
||||||
" nick are lurkers. The euphoria client doesn't display them in the"
|
" nick are lurkers. The euphoria client doesn't display them in the"
|
||||||
" nick list.\n"
|
" nick list.\n"
|
||||||
"This bot differentiates between people (L) and bots (N) who are"
|
"This bot differentiates between people (L) and bots (N) who are"
|
||||||
" lurking."
|
" lurking."
|
||||||
))
|
)
|
||||||
|
elif topic == "changelog":
|
||||||
self.add_help("changelog", (
|
text = (
|
||||||
"- add !recount command\n"
|
"- add !recount command\n"
|
||||||
"- fix bot counting incorrectly\n"
|
"- fix bot counting incorrectly\n"
|
||||||
))
|
"- port to rewrite-4 of yaboli\n"
|
||||||
|
"- add !detail and !manager commands\n"
|
||||||
self.help_specific = (
|
|
||||||
"Displays information about the clients in a room in its nick:\n"
|
|
||||||
"(<people>P <bots>B <lurkers>L <bot-lurkers>N)\n\n"
|
|
||||||
"!recount @{nick} - Recount people in the room\n\n"
|
|
||||||
"Created by @Garmy using yaboli.\n"
|
|
||||||
"For additional info, try \"!help @{nick} <topic>\". Topics:\n"
|
|
||||||
)
|
)
|
||||||
self.help_specific += self.list_help_topics()
|
else:
|
||||||
|
text = f"Topic {topic!r} does not exist."
|
||||||
|
|
||||||
self.register_command("recount", self.command_recount, specific=False)
|
await room.send(text, message.mid)
|
||||||
|
|
||||||
async def update_nick(self):
|
async def update_nick(self, room):
|
||||||
p = len(self.room.listing.get(types=["account", "agent"], lurker=False))
|
p = len(room.listing.get(types=["account", "agent"], lurker=False))
|
||||||
b = 1 + len(self.room.listing.get(types=["bot"], lurker=False))
|
b = 1 + len(room.listing.get(types=["bot"], lurker=False))
|
||||||
l = len(self.room.listing.get(types=["account", "agent"], lurker=True))
|
l = len(room.listing.get(types=["account", "agent"], lurker=True))
|
||||||
n = len(self.room.listing.get(types=["bot"], lurker=True))
|
n = len(room.listing.get(types=["bot"], lurker=True))
|
||||||
|
|
||||||
name = []
|
name = []
|
||||||
if p > 0: name.append(f"{p}P")
|
if p > 0: name.append(f"{p}P")
|
||||||
|
|
@ -60,43 +103,62 @@ class InfoBot(yaboli.Bot):
|
||||||
if n > 0: name.append(f"{n}N")
|
if n > 0: name.append(f"{n}N")
|
||||||
name = "\u0001(" + " ".join(name) + ")"
|
name = "\u0001(" + " ".join(name) + ")"
|
||||||
|
|
||||||
await self.set_nick(name)
|
await room.nick(name)
|
||||||
|
|
||||||
async def on_join(self, session):
|
async def connected(self, room, log):
|
||||||
await self.update_nick()
|
await self.update_nick(room)
|
||||||
await self.room.who()
|
|
||||||
await self.update_nick()
|
|
||||||
|
|
||||||
async def on_part(self, session):
|
async def join(self, room, session):
|
||||||
await self.update_nick()
|
await self.update_nick(room)
|
||||||
await self.room.who()
|
await room.who()
|
||||||
await self.update_nick()
|
await self.update_nick(room)
|
||||||
|
|
||||||
async def on_nick(self, session_id, user_id, from_nick, to_nick):
|
async def part(self, room, session):
|
||||||
await self.update_nick()
|
await self.update_nick(room)
|
||||||
await self.room.who()
|
await room.who()
|
||||||
await self.update_nick()
|
await self.update_nick(room)
|
||||||
|
|
||||||
async def on_snapshot(self, user_id, session_id, version, sessions,
|
async def nick(self, room, sid, uid, from_nick, to_nick):
|
||||||
messages, nick=None, pm_with_nick=None,
|
await self.update_nick(room)
|
||||||
pm_with_user_id=None):
|
await room.who()
|
||||||
# Not needed because we're updating the nick anyways.
|
await self.update_nick(room)
|
||||||
#super().on_snapshot(user_id, session_id, version, sessions, messages,
|
|
||||||
# nick, pm_with_nick, pm_with_user_id)
|
|
||||||
await self.update_nick()
|
|
||||||
|
|
||||||
async def command_recount(self, message, argstr):
|
@yaboli.command("recount", specific=True, noargs=True)
|
||||||
await self.room.who()
|
async def command_recount(self, room, message):
|
||||||
await self.update_nick()
|
await room.who()
|
||||||
await self.room.send("Recalibrated.", message.mid)
|
await self.update_nick(room)
|
||||||
|
await room.send("Recalibrated.", message.mid)
|
||||||
|
|
||||||
|
@yaboli.command("detail", specific=True, noargs=True)
|
||||||
|
async def command_detail(self, room, message):
|
||||||
|
sessions = room.listing.get() + [room.session]
|
||||||
|
sessions = sorted(sessions, key=lambda s: s.uid)
|
||||||
|
sessions = [self.format_session(s) for s in sessions]
|
||||||
|
text = "\n".join(sessions)
|
||||||
|
await room.send(text, message.mid)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def format_session(s):
|
||||||
|
is_staff = "yes" if s.is_staff 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}"
|
||||||
|
|
||||||
|
@yaboli.command("hosts", specific=True, noargs=False)
|
||||||
|
async def command_hosts(self, room, message, argstr):
|
||||||
|
flags, args, kwargs = self.parse_flags(self.parse_args(argstr))
|
||||||
|
sessions = room.listing.get() + [room.session]
|
||||||
|
sessions = [s for s in sessions if s.is_manager]
|
||||||
|
if "mention" in kwargs:
|
||||||
|
sessions = ["@" + mention(s.nick) for s in sessions]
|
||||||
|
else:
|
||||||
|
sessions = [s.nick for s in sessions]
|
||||||
|
text = "Hosts that are currently in this room:\n" + "\n".join(sessions)
|
||||||
|
await room.send(text, message.mid)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 2:
|
bot = InfoBot("()", "infobot.cookie")
|
||||||
print("USAGE:")
|
join_rooms.join_rooms(bot)
|
||||||
print(f" {sys.argv[0]} <room>")
|
asyncio.get_event_loop().run_forever()
|
||||||
return
|
|
||||||
|
|
||||||
run_bot(InfoBot, sys.argv[1])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue