mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-02 15:44:06 +01:00
ServiceBot: always show featured commands list in private, to prevent channel floods
This commit is contained in:
parent
1ac1e3eca6
commit
5c90cbe01f
32
utils.py
32
utils.py
@ -255,15 +255,24 @@ class ServiceBot():
|
|||||||
self.commands[name].append(func)
|
self.commands[name].append(func)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
def _show_command_help(self, irc, command):
|
def _show_command_help(self, irc, command, private=False):
|
||||||
|
"""
|
||||||
|
Shows help for the given command.
|
||||||
|
"""
|
||||||
|
def _reply(text):
|
||||||
|
"""
|
||||||
|
reply() wrapper to handle the private argument.
|
||||||
|
"""
|
||||||
|
self.reply(irc, text, private=private)
|
||||||
|
|
||||||
if command not in self.commands:
|
if command not in self.commands:
|
||||||
self.reply(irc, 'Error: Unknown command %r.' % command)
|
_reply('Error: Unknown command %r.' % command)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
funcs = self.commands[command]
|
funcs = self.commands[command]
|
||||||
if len(funcs) > 1:
|
if len(funcs) > 1:
|
||||||
self.reply(irc, 'The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
_reply('The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
||||||
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
||||||
for func in funcs:
|
for func in funcs:
|
||||||
doc = func.__doc__
|
doc = func.__doc__
|
||||||
mod = func.__module__
|
mod = func.__module__
|
||||||
@ -274,9 +283,9 @@ class ServiceBot():
|
|||||||
lines[0] = '\x02%s %s\x02' % (command, lines[0])
|
lines[0] = '\x02%s %s\x02' % (command, lines[0])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
# Then, just output the rest of the docstring to IRC.
|
# Then, just output the rest of the docstring to IRC.
|
||||||
self.reply(irc, line.strip())
|
_reply(line.strip())
|
||||||
else:
|
else:
|
||||||
self.reply(irc, "Error: Command %r doesn't offer any help." % command)
|
_reply("Error: Command %r doesn't offer any help." % command)
|
||||||
return
|
return
|
||||||
|
|
||||||
def help(self, irc, source, args):
|
def help(self, irc, source, args):
|
||||||
@ -315,19 +324,20 @@ class ServiceBot():
|
|||||||
self.reply(irc, 'Available commands include: %s' % ', '.join(cmds))
|
self.reply(irc, 'Available commands include: %s' % ', '.join(cmds))
|
||||||
self.reply(irc, 'To see help on a specific command, type \x02help <command>\x02.')
|
self.reply(irc, 'To see help on a specific command, type \x02help <command>\x02.')
|
||||||
else:
|
else:
|
||||||
self.reply(irc, 'This client doesn\'t provide any public commands.')
|
self.reply(irc, 'This service doesn\'t provide any public commands.')
|
||||||
|
|
||||||
# If there are featured commands, list them by showing the help for each.
|
# If there are featured commands, list them by showing the help for each.
|
||||||
|
# These definitions are sent in private to prevent flooding in channels.
|
||||||
if self.featured_cmds:
|
if self.featured_cmds:
|
||||||
self.reply(irc, " ")
|
self.reply(irc, " ", private=True)
|
||||||
self.reply(irc, 'Featured commands include:')
|
self.reply(irc, 'Featured commands include:', private=True)
|
||||||
for cmd in sorted(self.featured_cmds):
|
for cmd in sorted(self.featured_cmds):
|
||||||
if self.commands.get(cmd):
|
if self.commands.get(cmd):
|
||||||
# Only show featured commands that are both defined and loaded.
|
# Only show featured commands that are both defined and loaded.
|
||||||
# TODO: perhaps plugin unload should remove unused featured command
|
# TODO: perhaps plugin unload should remove unused featured command
|
||||||
# definitions automatically?
|
# definitions automatically?
|
||||||
self.reply(irc, " ")
|
self.reply(irc, " ", private=True)
|
||||||
self._show_command_help(irc, cmd)
|
self._show_command_help(irc, cmd, private=True)
|
||||||
|
|
||||||
def registerService(name, *args, **kwargs):
|
def registerService(name, *args, **kwargs):
|
||||||
"""Registers a service bot."""
|
"""Registers a service bot."""
|
||||||
|
Loading…
Reference in New Issue
Block a user