def config(bot, event, cmd=None, *args): if cmd == 'get' or cmd is None: config_args = list(args) value = bot.config.get_by_path(config_args) if config_args else dict(bot.config) elif cmd == 'set': config_args = list(args[:-1]) if len(args) >= 2: bot.config.set_by_path(config_args, json.loads(args[-1])) bot.config.save() value = bot.config.get_by_path(config_args) else: yield from DispatcherSingleton.unknown_command(bot, event) return else: yield from DispatcherSingleton.unknown_command(bot, event) return if value is None: value = 'Parameter does not exist!' config_path = ' '.join(k for k in ['config'] + config_args) segments = [hangups.ChatMessageSegment('{}:'.format(config_path), is_bold=True), hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)] segments.extend(UtilBot.text_to_segments(json.dumps(value, indent=2, sort_keys=True))) bot.send_message_segments(event.conv, segments)
def handle_command(self, event): """Handle command messages""" # Test if command handling is enabled if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): return # Parse message line_args = shlex.split(event.text, posix=False) i = 0 while i < len(line_args): line_args[i] = line_args[i].strip() if line_args[i] == '' or line_args[i] == '': line_args.remove(line_args[i]) else: i += 1 # Test if command length is sufficient if len(line_args) < 1: self.bot.send_message(event.conv, '{}: Not a valid command.'.format(event.user.full_name)) return # Test if user has permissions for running command if self._check_if_can_run_command(event, line_args[0].lower().replace(self.command_char, '')): # Run command yield from DispatcherSingleton.run(self.bot, event, self.command_char, *line_args[0:]) else: self.bot.send_message(event.conv, "Sorry {}, I can't let you do that.".format(event.user.full_name))
def handle_command(self, event): """Handle command messages""" # Test if command handling is enabled if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): return # Parse message line_args = shlex.split(event.text, posix=False) i = 0 while i < len(line_args): line_args[i] = line_args[i].strip() if line_args[i] == '' or line_args[i] == '': line_args.remove(line_args[i]) else: i += 1 # Test if command length is sufficient if len(line_args) < 1: self.bot.send_message(event.conv, '{}: Not a valid command.'.format(event.user.full_name)) return # Test if user has permissions for running command (and subcommand) if check_if_can_run_command(self.bot, event, line_args[0].lower().replace(self.command_char, '')): # Run command yield from DispatcherSingleton.run(self.bot, event, self.command_char, *line_args[0:]) else: self.bot.send_message(event.conv, "Sorry {}, I can't let you do that.".format(event.user.full_name))
def handle_command(self, event): """Handle command messages""" # Test if command handling is enabled if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): return # Parse message line_args = shlex.split(event.text, posix=False) i = 0 while i < len(line_args): line_args[i] = line_args[i].strip() if line_args[i] == '' or line_args[i] == '': line_args.remove(line_args[i]) else: i += 1 # Test if command length is sufficient if len(line_args) < 1: self.bot.send_message( event.conv, '{}: Not a valid command.'.format(event.user.full_name)) return for prev_command in self.command_cache: if prev_command[0] == event.user_id[0] and prev_command[ 1] == line_args[0] and (datetime.now() - prev_command[2] ).seconds < self.TIME_OUT: self.bot.send_message( event.conv, "Ignored duplicate command from %s." % event.user.full_name) return self.command_cache.append( (event.user_id[0], line_args[0], datetime.now())) # Test if user has permissions for running command (and subcommand) if check_if_can_run_command( self.bot, event, line_args[0].lower().replace(self.command_char, '')): # Run command yield from DispatcherSingleton.run(self.bot, event, self.command_char, *line_args[0:]) else: self.bot.send_message( event.conv, "Sorry {}, I can't let you do that.".format( event.user.full_name))