3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

games: Write .help handler

This commit is contained in:
Daniel Oaks 2016-04-08 12:02:49 +10:00 committed by James Lu
parent c2e3ce5bdf
commit f1b0981f87

View File

@ -27,15 +27,12 @@ class DataStore:
self._filename = os.path.abspath(os.path.expanduser(filename)) self._filename = os.path.abspath(os.path.expanduser(filename))
self._tmp_filename = self._filename + '.tmp' self._tmp_filename = self._filename + '.tmp'
log.debug('(db:{}) database path set to {}'.format(self.name, self._filename)) log.debug('(db:{}) database path set to {}'.format(self.name, self._filename))
self._format = db_format self._format = db_format
log.debug('(db:{}) format set to {}'.format(self.name, self._format)) log.debug('(db:{}) format set to {}'.format(self.name, self._format))
self._save_frequency = timedelta(**save_frequency).total_seconds() self._save_frequency = timedelta(**save_frequency).total_seconds()
log.debug('(db:{}) saving every {} seconds'.format(self.name, self._save_frequency)) log.debug('(db:{}) saving every {} seconds'.format(self.name, self._save_frequency))
def create_or_load(self): def create_or_load(self):
@ -163,9 +160,29 @@ class CommandHandler:
@staticmethod @staticmethod
def help_cmd(self, bot, irc, user, command): def help_cmd(self, bot, irc, user, command):
"[command] -- Help for the given commands" "[command] -- Help for the given commands"
print('COMMAND DETAILS:', command) if command.args.strip() == '':
# TODO(dan): Write help handler # regenerate command help if required
irc.proto.notice(user.uid, command.sender, '== Help ==') if self.command_help is None:
help = ['== Help ==']
for name, handler in sorted(self.commands.items()):
if hasattr(handler, '__doc__'):
help.append(' {}{} {}'.format(self.public_command_prefix, name, handler.__doc__))
self.command_help = help
# print out
for line in self.command_help:
irc.proto.notice(user.uid, command.sender, line)
else:
cmd = command.args.strip().split(' ', 1)[0].casefold()
if cmd.startswith(self.public_command_prefix):
cmd = cmd[len(self.public_command_prefix) - 1:]
handler = self.commands.get(cmd)
if handler:
irc.proto.notice(user.uid, command.sender, 'Help: {}{} {}'.format(self.public_command_prefix, cmd, handler.__doc__))
else:
irc.proto.notice(user.uid, command.sender, 'Help: command not found')
@staticmethod @staticmethod
def request_cmd(self, bot, irc, user, command): def request_cmd(self, bot, irc, user, command):