Search in sources :

Example 6 with GenericMessageEvent

use of org.pircbotx.hooks.types.GenericMessageEvent 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)

Example 7 with GenericMessageEvent

use of org.pircbotx.hooks.types.GenericMessageEvent in project LanteaBot by PC-Logix.

the class Give method initHook.

@Override
protected void initHook() {
    local_command = new Command("give", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "Target"), new CommandArgument(ArgumentTypes.STRING, "Item", "If this parameter is literally \"random\" a random item will be used."))) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, ArrayList<String> params) {
            String target_argument = this.argumentParser.getArgument("Target");
            String item_name = this.argumentParser.getArgument("Item");
            if (!target_argument.equals(IRCBot.getOurNick())) {
                Item item;
                if (item_name == null || item_name.equals("random")) {
                    System.out.println("Get random item");
                    item = Inventory.getRandomItem(false);
                } else
                    try {
                        item = new Item(StringEscapeUtils.escapeHtml4(item_name), true);
                    } catch (Exception e) {
                        item = null;
                    }
                if (item == null) {
                    Helper.sendAction(target, "searches through " + Helper.parseSelfReferral("his") + " inventory for a bit. \"I couldn't find anything...\"");
                    return new CommandChainStateObject();
                }
                int removeResult = Inventory.removeItem(item);
                if (removeResult == 0 || removeResult == Inventory.ERROR_ITEM_IS_PRESERVED)
                    Helper.sendAction(target, "gives " + target_argument + " " + StringEscapeUtils.unescapeHtml4(item.getName()) + " from " + Helper.parseSelfReferral("his") + " inventory");
                else if (removeResult == Inventory.ERROR_ITEM_IS_FAVOURITE)
                    Helper.sendMessage(target, "No! This is my favourite thing! I wont give it away!", nick);
                else if (removeResult == Inventory.ERROR_NO_ROWS_RETURNED)
                    Helper.sendMessage(target, "No item found to give away.", nick);
                else
                    Helper.sendMessage(target, "Something went wrong (" + removeResult + ")", nick);
            } else if (!item_name.equals(IRCBot.getOurNick())) {
                String add_attempt = Inventory.addItem(item_name, nick, false, false);
                if (add_attempt.equals("already has a few of those."))
                    Helper.sendAction(target, "politely declines, as " + Helper.parseSelfReferral("he") + " already has a few of those");
                else
                    Helper.sendAction(target, "accepts " + Inventory.fixItemName(item_name, true) + " and adds it to " + Helper.parseSelfReferral("his") + " inventory");
            }
            return new CommandChainStateObject();
        }
    };
    local_command.setHelpText("If the items is found in the inventory it is \"given\" to the target.");
    IRCBot.registerCommand(local_command);
}
Also used : CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Example 8 with GenericMessageEvent

use of org.pircbotx.hooks.types.GenericMessageEvent in project LanteaBot by PC-Logix.

the class Hiss method initCommands.

private void initCommands() {
    local_command = new Command("hiss", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING))) {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            String str = this.argumentParser.getArgument(0);
            if (str == null || str.equals("")) {
                Helper.sendMessage(target, "Snek?", nick);
            } else {
                Helper.sendMessage(target, str.replaceAll("s", "ss").replaceAll("S", "SS"));
            }
            return new CommandChainStateObject();
        }
    };
    local_command.registerAlias("snake");
    local_command.registerAlias("snek");
    local_command.setHelpText("Sneks the text");
}
Also used : Command(pcl.lc.irc.entryClasses.Command) CommandArgument(pcl.lc.irc.entryClasses.CommandArgument) CommandArgumentParser(pcl.lc.irc.entryClasses.CommandArgumentParser) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Example 9 with GenericMessageEvent

use of org.pircbotx.hooks.types.GenericMessageEvent in project LanteaBot by PC-Logix.

the class SWSpoilerGen method initHook.

@Override
protected void initHook() {
    words = new HashMap<>();
    words.put("1", new String[] { "Kyle Ren", "Malloc", "Darth Sebelius", "Theranos", "Lord Juul" });
    words.put("2", new String[] { "Kim Spacemeasurer", "Teen Yoda", "Dab Tweetdeck", "Yaz Progestin", "TI-83" });
    words.put("3", new String[] { "beige", "ochre", "mauve", "aquamarine", "taupe" });
    words.put("4", new String[] { "Sun Obliterator", "Moonsquisher", "World Eater", "Planet Zester", "Superconducting Supercollider" });
    words.put("5", new String[] { "blowing up a planet with a bunch of beams of energy that combine into one", "blowing up a bunch of planets with one beam of energy that splits into many", "cutting a planet in half and smashing the halves together like two cymbals", "increasing the CO2 levels in a planets atmosphere, causing rapid heating", "triggering the end credits before the movie is done" });
    words.put("6", new String[] { "Boba Fett", "Slacious Crumb", "The Space Slug", "The Bottom Half of Darth Maul", "YouTube Commenters" });
    words.put("7", new String[] { "a bow that shoots little Lightsaber-headed arrows", "X-Wings and TIE Fighters dodging the giant letters of the opening crawl", "a Sith educational display that uses force lightning to demonstate the dielectric breakdown of air", "Kylo Ren putting on another helmet over his smaller one", "a Sith car wash where the bristles on the brushes are little Lightsabers" });
    words.put("8", new String[] { "Luke", "Leia", "Han", "Obi-Wan", "A Random Junk Trader" });
    words.put("9", new String[] { "Poe", "BB-8", "Amilyn Holdo", "Laura Dern", "A Random Junk Trader", "That One Droid from the Jawa Sandcrawler that says Gronk" });
    local_command = new Command("swspoiler") {

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, String params) {
            Helper.AntiPings = Helper.getNamesFromTarget(target);
            Helper.sendMessage(target, spoilerParse(), nick, true);
            return new CommandChainStateObject();
        }
    };
    local_command.setHelpText("Generates a random spoiler for Star Wars");
    IRCBot.registerCommand(local_command);
}
Also used : Command(pcl.lc.irc.entryClasses.Command) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Example 10 with GenericMessageEvent

use of org.pircbotx.hooks.types.GenericMessageEvent in project LanteaBot by PC-Logix.

the class Seen method initHook.

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

        @Override
        public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, ArrayList<String> params) throws Exception {
            String dest;
            if (event.getClass().getName().equals("org.pircbotx.hooks.events.MessageEvent")) {
                dest = target;
            } else {
                dest = "query";
            }
            PreparedStatement getSeen = Database.getPreparedStatement("getLastSeen");
            String targetNick = this.argumentParser.getArgument("Nick");
            getSeen.setString(1, targetNick.toLowerCase());
            ResultSet results = getSeen.executeQuery();
            if (results.next()) {
                if (dest.equals("query")) {
                    event.respond(targetNick + " was last seen " + formatTime(System.currentTimeMillis() - results.getLong(1)) + "ago. Saying: " + ((results.getString(2).isEmpty()) ? "No Record" : results.getString(2)));
                } else {
                    Helper.sendMessage(dest, targetNick + " was last seen " + formatTime(System.currentTimeMillis() - results.getLong(1)) + "ago. " + ((results.getString(2) == null) ? "No Record" : results.getString(2)));
                }
            } else {
                if (dest.equals("query")) {
                    event.respond(targetNick + " has not been seen");
                } else {
                    event.getBot().sendIRC().message(dest, targetNick + " has not been seen");
                }
            }
            return new CommandChainStateObject();
        }
    };
    local_command.setHelpText("Tells you the last time a user was active.  Active means they sent a message");
    IRCBot.registerCommand(local_command);
    Database.addStatement("CREATE TABLE IF NOT EXISTS LastSeen(user PRIMARY KEY, timestamp, doing)");
    Database.addUpdateQuery(4, "ALTER TABLE LastSeen ADD doing DEFAULT NULL");
    Database.addPreparedStatement("updateLastSeen", "REPLACE INTO LastSeen(user, timestamp, doing) VALUES (?, ?, ?);");
    Database.addPreparedStatement("getLastSeen", "SELECT timestamp, doing FROM LastSeen WHERE LOWER(user) = ? GROUP BY LOWER(user) ORDER BY timestamp desc");
// I Have NO idea where these came from, or why they are here.
// Database.addPreparedStatement("updateInfo","REPLACE INTO Info(key, data, doing) VALUES (?, ?, ?);");
// Database.addPreparedStatement("getInfo","SELECT data FROM Info WHERE key = ?;");
// Database.addPreparedStatement("getInfoAll","SELECT key, data FROM Info;");
// Database.addPreparedStatement("removeInfo","DELETE FROM Info WHERE key = ?;");
}
Also used : Command(pcl.lc.irc.entryClasses.Command) CommandArgument(pcl.lc.irc.entryClasses.CommandArgument) ResultSet(java.sql.ResultSet) CommandArgumentParser(pcl.lc.irc.entryClasses.CommandArgumentParser) CommandChainStateObject(pcl.lc.utils.CommandChainStateObject) PreparedStatement(java.sql.PreparedStatement) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent)

Aggregations

GenericMessageEvent (org.pircbotx.hooks.types.GenericMessageEvent)73 CommandChainStateObject (pcl.lc.utils.CommandChainStateObject)58 Command (pcl.lc.irc.entryClasses.Command)51 CommandArgument (pcl.lc.irc.entryClasses.CommandArgument)34 CommandArgumentParser (pcl.lc.irc.entryClasses.CommandArgumentParser)34 PreparedStatement (java.sql.PreparedStatement)15 ResultSet (java.sql.ResultSet)15 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 MessageEvent (org.pircbotx.hooks.events.MessageEvent)5 PrivateMessageEvent (org.pircbotx.hooks.events.PrivateMessageEvent)5 SQLException (java.sql.SQLException)4 DecimalFormat (java.text.DecimalFormat)4 CommandRateLimit (pcl.lc.irc.entryClasses.CommandRateLimit)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 JSONException (org.json.JSONException)3 User (org.pircbotx.User)3 InetAddress (java.net.InetAddress)2