src/main/java/com/ircnet/service/clis/strategy/SQueryCommandList.java
/**
     * Handler for: /SQUERY Clis LIST
     *
     * @param from User who sent the SQUERY
     * @param message message with format: LIST [options] <mask>
     */
Handler for: /SQUERY Clis LIST
@param from User who sent the SQUERY
@param message message with format: LIST [options] 
Handler for : / SQUERY Clis LIST @param from User who sent the SQUERY @param message message with format : LIST [ options ]
@Override
    public void processCommand(User from, String message) {
        String nick = from.getNick();
        String[] parts = message.split(" ");
        int errorCount = 0;
        CommandLineParser parser = new DefaultParser();
        if (parts.length == 1) {
            notice(nick, "You did not specify a channel mask. Use /SQUERY %s HELP LIST", serviceName);
            return;
        }
        String[] requestArguments = Arrays.copyOfRange(parts, 1, parts.length);
        try {
            CommandLine commandLine = parser.parse(options, requestArguments);
            if (CollectionUtils.isEmpty(commandLine.getArgList())) {
                notice(nick, "You did not specify a channel mask. Use /SQUERY %s HELP LIST", serviceName);
                return;
            }
            Integer minUsers = null;
            Integer maxUsers = null;
            String topic = commandLine.getOptionValue("topic");
            boolean showTopicAuthor = false;
            boolean showModes = false;
            if (commandLine.hasOption("min")) {
                try {
                    minUsers = Integer.parseInt(commandLine.getOptionValue("min"));
                } catch (NumberFormatException e) {
                    notice(nick, "Argument of -min is not a number: '%s'", commandLine.getOptionValue("min"));
                    errorCount++;
                }
            }
            if (commandLine.hasOption("max")) {
                try {
                    maxUsers = Integer.parseInt(commandLine.getOptionValue("max"));
                } catch (NumberFormatException e) {
                    notice(nick, "Argument of -max is not a number: '%s'", commandLine.getOptionValue("max"));
                    errorCount++;
                }
            }
            String mask = commandLine.getArgList().get(0);
            if (commandLine.hasOption("show")) {
                String flags = commandLine.getOptionValue("show");
                if (!flags.matches("^[mt]+$")) {
                    notice(nick, "Invalid -show flags '%s'. Allowed flags: 'mt'", flags);
                    errorCount++;
                } else {
                    if (flags.indexOf('m') != -1) {
                        showModes = true;
                    }
                    if (flags.indexOf('t') != -1) {
                        showTopicAuthor = true;
                    }
                }
            }
            if (errorCount > 0) {
                notice(nick, "Your query contains %d errors. Use /SQUERY %s HELP LIST", errorCount, serviceName);
                return;
            }
            String querySummary = buildQuerySummary(nick, minUsers, maxUsers, topic, showModes, showTopicAuthor, mask);
            notice(nick, querySummary);
            notice(nick, "Returning a maximum of %d channel names.", maxResults);
            Collection<ChannelData> channels = channelService.find(null, mask, MatchType.REG_EXP, topic, minUsers, maxUsers, null, null);
            int actualResultCount = channels.size();
            channels = channels.stream().limit(maxResults).collect(Collectors.toList());
            for (ChannelData channel : channels) {
                StringBuilder response = new StringBuilder();
                response.append(String.format("%-50s", channel.getName()));
                if (showModes) {
                    response.append(String.format(" %-12s", channel.getModes()));
                }
                response.append(String.format("%c%3d%c:", 0x2, channel.getUserCount(), 0x2));
                if (channel.getTopic() != null) {
                    response.append(String.format(" %s", channel.getTopic()));
                }
                if (showTopicAuthor && channel.getTopicFrom() != null) {
                    response.append(String.format(" (%s)", channel.getTopicFrom()));
                }
                notice(nick, response.toString());
            }
            notice(nick, "Found %d visible channels.", actualResultCount);
        } catch (ParseException e) {
            LOGGER.error("Failed to parse '{}' from {}", message, from, e);
        }
    }
@ Override public void processCommand ( User from , String message ) { String nick = from . getNick ( ) ; String [ ] parts = message . split ( " " ) ; int errorCount = 0 ; CommandLineParser parser = new DefaultParser ( ) ; if ( parts . length == 1 ) { notice ( nick , "You did not specify a channel mask. Use /SQUERY %s HELP LIST" , serviceName ) ; return ; } String [ ] requestArguments = Arrays . copyOfRange ( parts , 1 , parts . length ) ; try { CommandLine commandLine = parser . parse ( options , requestArguments ) ; if ( CollectionUtils . isEmpty ( commandLine . getArgList ( ) ) ) { notice ( nick , "You did not specify a channel mask. Use /SQUERY %s HELP LIST" , serviceName ) ; return ; } Integer minUsers = null ; Integer maxUsers = null ; String topic = commandLine . getOptionValue ( "topic" ) ; boolean showTopicAuthor = false ; boolean showModes = false ; if ( commandLine . hasOption ( "min" ) ) { try { minUsers = Integer . parseInt ( commandLine . getOptionValue ( "min" ) ) ; } catch ( NumberFormatException e ) { notice ( nick , "Argument of -min is not a number: '%s'" , commandLine . getOptionValue ( "min" ) ) ; errorCount ++ ; } } if ( commandLine . hasOption ( "max" ) ) { try { maxUsers = Integer . parseInt ( commandLine . getOptionValue ( "max" ) ) ; } catch ( NumberFormatException e ) { notice ( nick , "Argument of -max is not a number: '%s'" , commandLine . getOptionValue ( "max" ) ) ; errorCount ++ ; } } String mask = commandLine . getArgList ( ) . get ( 0 ) ; if ( commandLine . hasOption ( "show" ) ) { String flags = commandLine . getOptionValue ( "show" ) ; if ( ! flags . matches ( "^[mt]+$" ) ) { notice ( nick , "Invalid -show flags '%s'. Allowed flags: 'mt'" , flags ) ; errorCount ++ ; } else { if ( flags . indexOf ( 'm' ) != - 1 ) { showModes = true ; } if ( flags . indexOf ( 't' ) != - 1 ) { showTopicAuthor = true ; } } } if ( errorCount > 0 ) { notice ( nick , "Your query contains %d errors. Use /SQUERY %s HELP LIST" , errorCount , serviceName ) ; return ; } String querySummary = buildQuerySummary ( nick , minUsers , maxUsers , topic , showModes , showTopicAuthor , mask ) ; notice ( nick , querySummary ) ; notice ( nick , "Returning a maximum of %d channel names." , maxResults ) ; Collection < ChannelData > channels = channelService . find ( null , mask , MatchType . REG_EXP , topic , minUsers , maxUsers , null , null ) ; int actualResultCount = channels . size ( ) ; channels = channels . stream ( ) . limit ( maxResults ) . collect ( Collectors . toList ( ) ) ; for ( ChannelData channel : channels ) { StringBuilder response = new StringBuilder ( ) ; response . append ( String . format ( "%-50s" , channel . getName ( ) ) ) ; if ( showModes ) { response . append ( String . format ( " %-12s" , channel . getModes ( ) ) ) ; } response . append ( String . format ( "%c%3d%c:" , 0x2 , channel . getUserCount ( ) , 0x2 ) ) ; if ( channel . getTopic ( ) != null ) { response . append ( String . format ( " %s" , channel . getTopic ( ) ) ) ; } if ( showTopicAuthor && channel . getTopicFrom ( ) != null ) { response . append ( String . format ( " (%s)" , channel . getTopicFrom ( ) ) ) ; } notice ( nick , response . toString ( ) ) ; } notice ( nick , "Found %d visible channels." , actualResultCount ) ; } catch ( ParseException e ) { LOGGER . error ( "Failed to parse '{}' from {}" , message , from , e ) ; } }
Handler for: /SQUERY Clis LIST
 @param from User who sent the SQUERY
 @param message message with format: LIST [options] <mask>
Handler for : / SQUERY Clis LIST @param from User who sent the SQUERY @param message message with format : LIST [ options ] <mask >