Deal with leading "@" in --name option
This commit is contained in:
parent
fc5cc2f0d6
commit
89dbed8aee
1 changed files with 8 additions and 6 deletions
14
infobot.py
14
infobot.py
|
|
@ -17,7 +17,7 @@ class InfoBot(yaboli.Bot):
|
||||||
"--list=<who> : list user names and client/session ids\n"
|
"--list=<who> : list user names and client/session ids\n"
|
||||||
"--name=<name> : list info for users with the name specified\n"
|
"--name=<name> : list info for users with the name specified\n"
|
||||||
"<who> can be: people, bots, lurkers, all\n"
|
"<who> can be: people, bots, lurkers, all\n"
|
||||||
"<name> is the name of the person (without leading '@')\n\n"
|
"<name> is the name of the person\n\n"
|
||||||
"Shows different information about the clients connected to the\n"
|
"Shows different information about the clients connected to the\n"
|
||||||
"current room."))
|
"current room."))
|
||||||
|
|
||||||
|
|
@ -52,16 +52,17 @@ class InfoBot(yaboli.Bot):
|
||||||
|
|
||||||
elif ("name" in options and options["name"] is not True) or "list" in options:
|
elif ("name" in options and options["name"] is not True) or "list" in options:
|
||||||
clients = []
|
clients = []
|
||||||
msg = ""
|
|
||||||
|
|
||||||
if "name" in options:
|
if "name" in options:
|
||||||
name = self.room.mentionable(options["name"]).lower()
|
name = self.room.mentionable(options["name"]).lower()
|
||||||
|
|
||||||
if name[:1] == "@":
|
|
||||||
msg += "Are you sure the name is \"{}\"? You might want to omit the @.\n\n"
|
|
||||||
|
|
||||||
clients = [c for c in self.room.get_sessions()
|
clients = [c for c in self.room.get_sessions()
|
||||||
if self.room.mentionable(c.name).lower() == name]
|
if self.room.mentionable(c.name).lower() == name]
|
||||||
|
|
||||||
|
if name[:1] == "@":
|
||||||
|
name = name[1:]
|
||||||
|
clients.extend([c for c in self.room.get_sessions()
|
||||||
|
if self.room.mentionable(c.name).lower() == name])
|
||||||
|
|
||||||
elif "list" in options:
|
elif "list" in options:
|
||||||
if options["list"] is True or options["list"] == "all":
|
if options["list"] is True or options["list"] == "all":
|
||||||
|
|
@ -74,6 +75,7 @@ class InfoBot(yaboli.Bot):
|
||||||
clients = self.room.get_lurkers()
|
clients = self.room.get_lurkers()
|
||||||
|
|
||||||
if clients:
|
if clients:
|
||||||
|
msg = ""
|
||||||
for client in sorted(clients, key=lambda c: c.name.lower()):
|
for client in sorted(clients, key=lambda c: c.name.lower()):
|
||||||
msg += "id={}, session_id={}, name={}\n".format(
|
msg += "id={}, session_id={}, name={}\n".format(
|
||||||
repr(client.id),
|
repr(client.id),
|
||||||
|
|
@ -83,7 +85,7 @@ class InfoBot(yaboli.Bot):
|
||||||
|
|
||||||
msg = msg[:-1] # remove trailing newline
|
msg = msg[:-1] # remove trailing newline
|
||||||
else:
|
else:
|
||||||
msg += "No clients"
|
msg = "No clients"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
people = len(self.room.get_people())
|
people = len(self.room.get_people())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue