Search in sources :

Example 1 with CommandChainStateObject

use of pcl.lc.utils.CommandChainStateObject in project LanteaBot by PC-Logix.

the class Translator method initCommands.

private void initCommands() {
    local_command = new Command("translate", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "Text"), new CommandArgument(ArgumentTypes.STRING, "FromLanguage", "If this argument is omitted the API will try to determine it automatically."), new CommandArgument(ArgumentTypes.STRING, "ToLanguage", "If this argument is omitted the API will try to determine it automatically.")), new CommandRateLimit(5)) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            String str = this.argumentParser.getArgument("Text");
            String from = this.argumentParser.getArgument("FromLanguage");
            String to = this.argumentParser.getArgument("ToLanguage");
            if (to == null || to.equals(""))
                to = "auto";
            if (from == null || from.equals(""))
                from = "auto";
            Helper.sendMessage(target, doTranslate(from, to, str));
            return new CommandChainStateObject(CommandChainState.FINISHED);
        }
    };
    local_command.registerAlias("t");
}
Also used : CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Example 2 with CommandChainStateObject

use of pcl.lc.utils.CommandChainStateObject in project LanteaBot by PC-Logix.

the class Weather method initHook.

@Override
protected void initHook() {
    local_command = new Command("weather", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "Location"))) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
            Helper.sendMessage(target, getWeather(this.argumentParser.getArgument("Location")));
            return new CommandChainStateObject();
        }
    };
    local_command.registerAlias("w");
    local_command.setHelpText("Returns weather data for the supplied postal code, or Place name");
    IRCBot.registerCommand(local_command);
}
Also used : Command(pcl.lc.irc.entryClasses.Command) XPathExpressionException(javax.xml.xpath.XPathExpressionException) CommandArgument(pcl.lc.irc.entryClasses.CommandArgument) CommandArgumentParser(pcl.lc.irc.entryClasses.CommandArgumentParser) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) SAXException(org.xml.sax.SAXException)

Example 3 with CommandChainStateObject

use of pcl.lc.utils.CommandChainStateObject in project LanteaBot by PC-Logix.

the class WhoPinged method initHook.

@Override
protected void initHook() {
    Database.addStatement("CREATE TABLE IF NOT EXISTS Pings(id INTEGER PRIMARY KEY, whowaspinged, whopinged, message, time, channel)");
    Database.addPreparedStatement("addPing", "INSERT INTO Pings(whowaspinged, whopinged, message, time, channel) VALUES (?,?,?,?,?);");
    Database.addPreparedStatement("getPings", "SELECT id, whopinged, message, time, channel FROM Pings WHERE LOWER(whowaspinged) = ?;");
    Database.addPreparedStatement("getAllPings", "SELECT id, time FROM Pings;");
    Database.addPreparedStatement("delPings", "DELETE FROM Pings WHERE id = ?;");
    command_WhoPinged = new Command("whopinged") {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            try {
                PreparedStatement statement = Database.getPreparedStatement("getPings");
                statement.setString(1, nick.toLowerCase());
                ResultSet results = statement.executeQuery();
                if (Config.httpdEnable.equals("true") && results.next()) {
                    Helper.sendMessage(target, "Who Pinged you: " + httpd.getBaseDomain() + "/whopinged?nick=" + nick, nick);
                } else if (!results.next()) {
                    Helper.sendMessage(target, "No pings! :(");
                }
            } catch (Exception e) {
                Helper.sendMessage(target, "Error: " + e.getClass() + " " + e.getMessage());
                e.printStackTrace();
            }
            return new CommandChainStateObject();
        }
    };
    command_WhoPinged.setHelpText("Shows you the last pings you had.");
    command_ClearPings = new Command("clearpings") {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            try {
                PreparedStatement statement = Database.getPreparedStatement("delPings");
                statement.setString(1, nick);
                statement.execute();
                Helper.sendMessage(target, "Ok");
            } catch (Exception e) {
                Helper.sendMessage(target, "Error: " + e.getClass() + " " + e.getMessage());
                e.printStackTrace();
            }
            return new CommandChainStateObject();
        }
    };
    command_ClearPings.setHelpText("Clears your pings from the DB");
    IRCBot.registerCommand(command_WhoPinged);
    IRCBot.registerCommand(command_ClearPings);
    ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
    executor = ses.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            try {
                long epoch = System.currentTimeMillis();
                PreparedStatement getPings = Database.getPreparedStatement("getAllPings");
                ResultSet results = getPings.executeQuery();
                while (results.next()) {
                    if ((results.getLong(2) + 259200000) <= epoch) {
                        PreparedStatement delPings = Database.getPreparedStatement("delPings");
                        delPings.setLong(1, results.getLong(1));
                        delPings.execute();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 0, 1, TimeUnit.SECONDS);
    httpd.registerContext("/whopinged", new WhoPingedHandler(), "WhoPinged");
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Command(pcl.lc.irc.entryClasses.Command) ResultSet(java.sql.ResultSet) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) PreparedStatement(java.sql.PreparedStatement) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) IOException(java.io.IOException)

Example 4 with CommandChainStateObject

use of pcl.lc.utils.CommandChainStateObject in project LanteaBot by PC-Logix.

the class Exclamation method initCommands.

private void initCommands() {
    CommandRateLimit limit = new CommandRateLimit(0, 5, 0, true, false);
    command_curse_word = new Command("curseword", limit) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            Helper.sendMessage(target, getRandomExpression(TypeFilter.CURSE_WORD) + TablesOfRandomThings.getRandomExclamations(true, false), nick);
            return new CommandChainStateObject();
        }
    };
    command_curse_word.registerAlias("curses");
    command_curse_word.registerAlias("cursewd");
    command_curse_word.registerAlias("cursew");
    command_curse_word.registerAlias("swear");
    command_curse_word.registerAlias("swearword");
    command_curse_word.setHelpText("Holy manbats Batman!");
    command_exclamation = new Command("exclamation", limit) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            Helper.sendMessage(target, getRandomExpression(TypeFilter.ALL) + TablesOfRandomThings.getRandomExclamations(true, false), nick);
            return new CommandChainStateObject();
        }
    };
    command_exclamation.registerAlias("excl");
    command_exclamation.setHelpText("Wot in tarnation?!");
}
Also used : Command(pcl.lc.irc.entryClasses.Command) CommandRateLimit(pcl.lc.irc.entryClasses.CommandRateLimit) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Example 5 with CommandChainStateObject

use of pcl.lc.utils.CommandChainStateObject in project LanteaBot by PC-Logix.

the class GithubInfo method initHook.

@Override
protected void initHook() {
    local_command = new Command("github", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "State")), new CommandRateLimit(10), Permissions.MOD) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            String state = this.argumentParser.getArgument("State").toLowerCase();
            if (state.equals("disable") || state.equals("enable")) {
                Helper.toggleCommand("github", target, state);
            } else {
                String isEnabled = Helper.isEnabledHere(target, "github") ? "enabled" : "disabled";
                Helper.sendMessage(target, "GitHub Info is " + isEnabled + " in this channel", nick);
            }
            return new CommandChainStateObject();
        }
    };
    local_command.setHelpText("Github Ticket info");
    IRCBot.registerCommand(local_command);
}
Also used : CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Aggregations

CommandChainStateObject (pcl.lc.utils.CommandChainStateObject)59 GenericMessageEvent (org.pircbotx.hooks.types.GenericMessageEvent)58 Command (pcl.lc.irc.entryClasses.Command)42 CommandArgument (pcl.lc.irc.entryClasses.CommandArgument)30 CommandArgumentParser (pcl.lc.irc.entryClasses.CommandArgumentParser)30 ResultSet (java.sql.ResultSet)10 PreparedStatement (java.sql.PreparedStatement)9 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4 CommandRateLimit (pcl.lc.irc.entryClasses.CommandRateLimit)4 DecimalFormat (java.text.DecimalFormat)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 SQLException (java.sql.SQLException)2 Random (java.util.Random)2 NamingException (javax.naming.NamingException)2 Attributes (javax.naming.directory.Attributes)2