use of pcl.lc.irc.entryClasses.CommandArgument 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.irc.entryClasses.CommandArgument 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");
}
use of pcl.lc.irc.entryClasses.CommandArgument 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 = ?;");
}
use of pcl.lc.irc.entryClasses.CommandArgument in project LanteaBot by PC-Logix.
the class LookUp method initHook.
@Override
protected void initHook() {
local_command_lookup = new Command("lookup", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "Address"), new CommandArgument(ArgumentTypes.STRING, "RecordType"))) {
@Override
public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, ArrayList<String> params) {
String address = this.argumentParser.getArgument("Address");
try {
InetAddress inetAddress;
String recordType = this.argumentParser.getArgument("RecordType");
if (recordType == null)
recordType = "A";
// if first character is a digit then assume is an address
if (Character.isDigit(address.charAt(0))) {
// convert address from string representation to byte array
byte[] b = new byte[4];
String[] bytes = address.split("[.]");
for (int i = 0; i < bytes.length; i++) {
b[i] = new Integer(bytes[i]).byteValue();
}
// get Internet Address of this host address
inetAddress = InetAddress.getByAddress(b);
} else {
// get Internet Address of this host name
inetAddress = InetAddress.getByName(address);
}
// get the default initial Directory Context
InitialDirContext iDirC = new InitialDirContext();
// get the DNS records for inetAddress
Attributes attributes = iDirC.getAttributes("dns:/" + inetAddress.getHostName());
// get an enumeration of the attributes and print them out
NamingEnumeration attributeEnumeration = attributes.getAll();
while (attributeEnumeration.hasMore()) {
String record = "" + attributeEnumeration.next();
String[] thisType = record.split(":", 2);
if (thisType[0].equalsIgnoreCase(recordType) || recordType.equalsIgnoreCase("any")) {
Helper.sendMessage(target, "" + record);
}
}
attributeEnumeration.close();
} catch (UnknownHostException exception) {
Helper.sendMessage(target, "ERROR: No Internet Address for '" + address + "'");
} catch (NamingException exception) {
Helper.sendMessage(target, "ERROR: No DNS record for '" + address + "'");
Helper.sendMessage(target, exception.getExplanation() + " Resolved: " + exception.getResolvedName() + " Unresolved: " + exception.getRemainingName());
exception.printStackTrace();
}
// Helper.sendMessage(target, output.replace(params.get(0) + "/", " ").replaceAll("((?::0\\b){2,}):?(?!\\S*\\b\\1:0\\b)(\\S*)", "::$2"), nick);
return new CommandChainStateObject();
}
};
local_command_lookup.setHelpText("Returns DNS information");
local_command_rdns = new Command("rdns") {
@Override
public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, ArrayList<String> params) throws UnknownHostException {
InetAddress addr = InetAddress.getByName(params.get(0));
String host = addr.getCanonicalHostName();
String output = "Reverse DNS Info for " + params.get(0) + " " + host;
Helper.sendMessage(target, output, nick);
return new CommandChainStateObject();
}
};
local_command_rdns.setHelpText("Returns Reverse DNS information");
IRCBot.registerCommand(local_command_lookup);
IRCBot.registerCommand(local_command_rdns);
}
use of pcl.lc.irc.entryClasses.CommandArgument in project LanteaBot by PC-Logix.
the class MCInfo method initCommands.
private void initCommands() {
local_command = new Command("mcinfo", new CommandArgumentParser(1, new CommandArgument(ArgumentTypes.STRING, "Address"), new CommandArgument(ArgumentTypes.INTEGER, "Port"))) {
@Override
public CommandChainStateObject onExecuteSuccess(Command command, String nick, String target, GenericMessageEvent event, ArrayList<String> params) throws IOException {
String server = this.argumentParser.getArgument("Address");
int port = this.argumentParser.getInt("Port");
if (port <= 0)
port = 25565;
System.out.println(server + ":" + port);
MinecraftPingReply data;
try {
data = new MinecraftPing().getPing(server, port);
Helper.sendMessage(target, "Server info: Version: " + data.getVersion() + " MOTD: " + data.getMotd() + " Players: " + data.getOnlinePlayers() + "/" + data.getMaxPlayers(), nick);
} catch (UnknownHostException e) {
Helper.sendMessage(target, "Server could not be found.", nick);
} catch (SocketTimeoutException e) {
Helper.sendMessage(target, "Connection timed out on port " + port + ". " + ((port == 25565) ? "Does the server use a custom port?" : "Did you specify the right port?"), nick);
}
return new CommandChainStateObject();
}
};
local_command.setHelpText("Returns information about a MC Server");
}
Aggregations