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");
}
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);
}
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");
}
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?!");
}
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);
}
Aggregations