Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mkyong.reflection;
- import org.jibble.pircbot.*;
- import com.rmtheis.yandtran.*;
- import com.rmtheis.yandtran.detect.Detect;
- import com.rmtheis.yandtran.translate.Translate;
- import java.io.*;
- import java.text.*;
- import java.nio.charset.Charset;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.Arrays;
- import java.util.regex.*;
- import com.google.code.chatterbotapi.*;
- import com.fathzer.soft.javaluator.*;
- public class MyBot extends PircBot {
- String prefix = "!";
- boolean jokeCommands = true;
- boolean chngCMDRan = false;
- ArrayList<String> playerList = new ArrayList<>();
- //boolean spinStarted = false;
- String[] dictionary = {": i don't know what \"%s\" is, do i look like a dictionary?", ": Go look it up yourself.", ": Why not use your computer and look \"%s\" up", ": Google it", "Nope.", "Get someone else to do it", "Why not get that " + Colors.RED + " Other bot" + Colors.NORMAL + " to do it?"};
- String[] commands = {"HelpMe", " time", " Hello", " RandomNum", " version", " Spin", " StringToBytes", " temp", " chat", " Joke: Splatoon", "Joke: Attempt", " Joke: Stfu", " Joke: potato-chan", " Joke: whatIs?", "Joke: getFinger"};
- String currentNick = "Lil-G";
- String currentUsername = "lilggamegenui";
- byte[] bytes = {-snip-};
- final String PASSWORD = new String(bytes);
- final int BLOCKS = 128;
- final int BLOCKSMB = 8*BLOCKS;
- final int BLOCKSGB = 8192*BLOCKS;
- int i = 0;
- ChatterBotFactory factory = new ChatterBotFactory();
- ChatterBot cleverBot;
- ChatterBotSession cleverBotsession;
- boolean cleverBotInt;
- ChatterBot pandoraBot;
- ChatterBotSession pandoraBotsession;
- boolean pandoraBotInt;
- String currChannel = null;
- boolean debugMode = false;
- DoubleEvaluator calc = new DoubleEvaluator();
- StaticVariableSet<Double> variables = new StaticVariableSet<>();
- // yandex api trnsl.1.1.20150924T011621Z.e06050bb431b7175.e5452b78ee8d11e4b736035e5f99f2831a57d0e2
- public MyBot(String name, String userName, boolean debugMode) {
- this.setName(name);
- this.setLogin(userName);
- this.setMessageDelay(1000);
- this.setDebugMode(debugMode);
- }
- public void onConnect(){
- identify(PASSWORD);
- sendRawLine("MODE Lil-G|bot +Bx");
- joinChannel("#Lil-G|bot");
- if(!debugMode) {
- joinChannel("#pokemon");
- joinChannel("#retro");
- joinChannel("#retrotech");
- //joinChannel("#ssrg");
- joinChannel("#SSB");
- //joinChannel("#tcrf");
- }
- sendRawLine("cs op #Lil-G|bot " + getNick());
- sendRawLine("cs op #Lil-G|bot Lil-G");
- sendRawLine("cs op #SSB " + getNick());
- sendRawLine("cs op #SSB Lil-G");
- }
- public void onMessage(String channel, String sender, String login, String hostname, String message) {
- currChannel = channel;
- List<String> argLog = splitMessage(message);
- log(argLog.toString());
- String[] arg = argLog.toArray(new String[argLog.size()]);
- // !helpme
- if (arg[0].equalsIgnoreCase(prefix + "helpme")){
- if (message.equalsIgnoreCase(prefix + "helpme")){
- sendMessage(channel,"List of commands so far.");
- ArrayList<String> cmdhelp = new ArrayList<>(Arrays.asList(commands));
- sendMessage(channel, cmdhelp.toString());
- }
- if (arg[1].equalsIgnoreCase("Helpme")){
- sendMessage(channel, sender + " , Really? " + "ಠ_ಠ");
- }
- if (arg[1].equalsIgnoreCase("time")){
- sendMessage(channel,"Displays info from the Date class");
- }
- if (arg[1].equalsIgnoreCase("Hello")){
- sendMessage(channel,"Just your average \"hello world!\" program");
- }
- if (arg[1].equalsIgnoreCase("Attempt")){
- sendMessage(channel,"Its a inside-joke to my friends in school. If i'm not away, ask me and i'll tell you about it.");
- }
- if (arg[1].equalsIgnoreCase("RandomNum")){
- sendMessage(channel,"Creates a random number between the 2 integers");
- sendMessage(channel,"Usage: first number sets the minimum number, second sets the maximum");
- }
- if (arg[1].equalsIgnoreCase("version")){
- sendMessage(channel,"Displays the version of the bot");
- }
- if (arg[1].equalsIgnoreCase("Spin")){
- sendMessage(channel,"Russian Roulette on irc. For more info do " + prefix + "spin help");
- }
- if (arg[1].equalsIgnoreCase("StringToBytes")){
- sendMessage(channel,"Converts a String into a Byte array");
- }
- if (arg[1].equalsIgnoreCase("temp")){
- sendMessage(channel,"Converts a temperature unit to another unit.");
- sendMessage(channel,"Usage: First parameter is the unit its in. Second parameter is the unit to convert to. Third parameter is the number to convert to.");
- }
- if (arg[1].equalsIgnoreCase("chat")){
- sendMessage(channel,"This command functions like ELIZA. Talk to it and it talks back.");
- sendMessage(channel,"Usage: First parameter defines what service to use. it supports CleverBot, PandoraBot, and JabberWacky (JabberWacky not yet implemented). Second parameter is the message to send. Could also be the special param \"\\setup\" to actually start the bot.");
- }
- }
- // !Time - Tell the time
- if (message.equalsIgnoreCase(prefix + "time")) {
- String time = new java.util.Date().toString();
- sendMessage(channel, sender + ": The time is now " + time);
- }
- // !calcj - calculate a expression
- if (arg[0].equalsIgnoreCase(prefix + "calcJ")) {
- double eval = 0;
- if(arg.length > 3) {
- double x = 0;
- eval = calc.evaluate(arg[1]);
- }
- sendMessage(channel, sender + ": " + eval);
- }
- // !Time - Tell the time
- if ((message.contains("hi") || message.contains("hey") || message.contains("hello")) && message.contains(getNick())) {
- sendMessage(channel, sender + ": I'm a bot");
- }
- // !StringToBytes - convert a String into a Byte array
- if (arg[0].equalsIgnoreCase(prefix + "StringToBytes")) {
- sendMessage(channel, sender + ": " + getBytes(arg[1]));
- }
- // !chat - chat's with a internet conversation bot
- if (arg[0].equalsIgnoreCase(prefix + "chat")) {
- if (arg[1].equalsIgnoreCase("clever")){
- if (arg[2].equalsIgnoreCase("\\setup")){
- try {
- cleverBot = factory.create(ChatterBotType.CLEVERBOT);
- cleverBotsession = cleverBot.createSession();
- cleverBotInt = true;
- sendNotice(sender, "CleverBot started");
- } catch(Exception e){
- sendMessage(channel, "Error: Could not create clever bot session. Error was: " + e);
- }
- }
- else{
- if (cleverBotInt) {
- try {
- sendMessage(channel, sender + ": " + botTalk("clever", arg[2]));
- } catch (Exception e) {
- sendMessage(channel, "Error: Problem with bot. Error was: " + e);
- }
- }
- else {
- sendMessage(channel, sender + ": You have to start CleverBot before you can talk to it. star it with \\setup");
- }
- }
- } else if (arg[1].equalsIgnoreCase("pandora")) {
- if (arg[2].equalsIgnoreCase("\\setup")) {
- try {
- pandoraBot = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
- pandoraBotsession = pandoraBot.createSession();
- pandoraBotInt = true;
- sendNotice(sender, "PandoraBot started");
- } catch(Exception e){
- sendMessage(channel, "Error: Could not create pandora bot session. Error was: " + e);
- }
- } else {
- if (pandoraBotInt) {
- try {
- sendMessage(channel, sender + ": " + botTalk("pandora", arg[2]));
- } catch (Exception e) {
- sendMessage(channel, "Error: Problem with bot. Error was: " + e);
- }
- }
- else {
- sendMessage(channel, sender + ": You have to start PandoraBot before you can talk to it. start it with \\setup");
- }
- }
- }
- }
- // !temp - Converts a unit of temperature to another
- if (arg[0].equalsIgnoreCase(prefix + "temp")) {
- int temp = Integer.parseInt(arg[3]);
- double ans = 0;
- String unit = "err";
- if(arg[1].equalsIgnoreCase("F")){
- if(arg[2].equalsIgnoreCase("C")){
- ans = (temp - 32)*5/9;
- unit = "C";
- }
- else if(arg[2].equalsIgnoreCase("K")){
- ans = (temp - 32) * 5/9 + 273.15;
- unit = "K";
- }
- }
- else if(arg[1].equalsIgnoreCase("C")){
- if(arg[2].equalsIgnoreCase("F")){
- ans = (temp * 9/5) + 32;
- unit = "F";
- }
- else if(arg[2].equalsIgnoreCase("K") && temp < 0){
- ans = temp + 273.15;
- unit = "K";
- }
- }
- else if(arg[1].equalsIgnoreCase("K")){
- if(arg[2].equalsIgnoreCase("F")){
- ans = (temp - 273.15) * 9/5 + 32;
- unit = "F";
- }
- else if(arg[2].equalsIgnoreCase("C")){
- ans = temp - 273.15;
- unit = "C";
- }
- }
- sendMessage(channel, sender + ": " + ans + unit);
- }
- // !blockconv - Converts blocks to bytes
- if (arg[0].equalsIgnoreCase(prefix + "blockconv")) {
- int data = Integer.parseInt(arg[3]);
- double ans = 0;
- String unit = "err";
- if(arg[1].equalsIgnoreCase("blocks")){
- if(arg[2].equalsIgnoreCase("kb")){
- ans = BLOCKS*data;
- unit = "KB";
- }
- }
- else if(arg[1].equalsIgnoreCase("kb")){
- if(arg[2].equalsIgnoreCase("blocks")) {
- ans = data/BLOCKS;
- unit = "Blocks";
- }
- }
- else if(arg[1].equalsIgnoreCase("mb")){
- if(arg[2].equalsIgnoreCase("blocks")){
- ans = data/BLOCKSMB;
- unit = "Blocks";
- }
- }
- else if(arg[1].equalsIgnoreCase("gb")){
- if(arg[2].equalsIgnoreCase("blocks")){
- ans = data/BLOCKSGB;
- unit = "Blocks";
- }
- }
- sendMessage(channel, sender + ": " + ans + unit);
- sendMessage(channel, "NOTICE: this command currently doesn't work like it should. The only conversion that works is blocks to kb and kb to blocks");
- }
- // !Hello - Standard "Hello world" command
- if (message.equalsIgnoreCase(prefix + "hello")){
- sendMessage(channel, sender + ": Hello World!");
- }
- // !Bot - Explains that "yes this is a bot"
- if (message.equalsIgnoreCase(prefix + "bot")){
- sendMessage(channel, sender + ": Yes, this is "+ currentNick + "'s bot.");
- }
- // !getname - gets the name of the bot
- if (message.equalsIgnoreCase(prefix + "getname")){
- sendMessage(channel, getName());
- }
- // !login - attempts to login to nickserv
- if (message.equalsIgnoreCase(prefix + "login")){
- sendRawLine("ns identify " + PASSWORD);
- sendRawLine("cs op #Lil-G|bot " + getNick());
- sendRawLine("cs op #Lil-G|bot Lil-G");
- sendRawLine("cs op #SSB " + getNick());
- sendRawLine("cs op #SSB Lil-G");
- }
- // !getLogin - gets the login of the bot
- if (message.equalsIgnoreCase(prefix + "getLogin")){
- sendMessage(channel, getLogin());
- }
- // !getID - gets the ID of the user
- if (arg[0].equalsIgnoreCase(prefix + "getID")){
- sendMessage(channel, "You are :" + findIn(getUsers(channel), arg[1]));
- }
- // !RandomNum - Gives the user a random Number
- if (arg[0].equalsIgnoreCase(prefix + "randomnum")){
- long num1, num2;
- if(arg[1].contains("0x")){
- num1 = Long.parseLong(arg[1], 16);
- }
- else{
- num1 = Long.parseLong(arg[1], 10);
- }
- if(arg[2].contains("0x")){
- num2 = Long.parseLong(arg[2], 16);
- }
- else{
- num2 = Long.parseLong(arg[2], 10);
- }
- sendMessage(channel, sender + ": " + randInt((int) num1, (int) num2));
- }
- // !version - Displays what version the bot is on
- if (message.equalsIgnoreCase(prefix + "version")){
- sendMessage(channel, sender + ": " + getVersion());
- try
- {
- Process p=Runtime.getRuntime().exec("java -version");
- p.waitFor();
- BufferedReader reader=new BufferedReader(
- new InputStreamReader(p.getInputStream()));
- String line;
- while((line = reader.readLine()) != null)
- {
- sendMessage(channel, line);
- }
- }
- catch(Exception e1) {
- sendMessage(channel, "Error: " + e1);
- }
- }
- // !ChngCMD - Changes the command prefix when it isn't the standard "!"
- if (arg[0].equalsIgnoreCase("!chngcmd") && !prefix.equals("!")){
- if(checkPerm(sender, hostname, login)){
- prefix = arg[1];
- sendMessage(channel, sender + ": Command variable is now \"" + prefix + "\"");
- chngCMDRan = true;
- }
- else {
- permError(sender, "can change the command character");
- }
- }
- // !ChngCMD - Changes the command prefix
- if (arg[0].equalsIgnoreCase(prefix + "chngcmd") && !chngCMDRan){
- if(checkPerm(sender, hostname, login)){
- prefix = arg[1];
- sendMessage(channel, sender + ": Command variable is now \"" + prefix + "\"");
- }
- else {
- permError(sender, "can change the command character");
- }
- }
- chngCMDRan = false;
- // !Saythis - Tells the bot to say someting
- if (arg[0].equalsIgnoreCase(prefix + "saythis")){
- if(checkPerm(sender, hostname, login)){
- sendMessage(channel, arg[1]);
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- // !ToSciNo - converts a number to scientific notation
- if (arg[0].equalsIgnoreCase(prefix + "ToSciNo")){
- NumberFormat formatter = new DecimalFormat("0.######E0");
- long num = Long.parseLong(arg[1]);
- try {
- sendMessage(channel, formatter.format(num));
- } catch (Exception e) {
- sendError(channel, e);
- log(e.toString());
- }
- }
- // !Trans - Translate from 1 language to another
- if (arg[0].equalsIgnoreCase(prefix + "trans")){
- String text = null;
- YandexTranslatorAPI.setKey("trnsl.1.1.20150924T011621Z.e06050bb431b7175.e5452b78ee8d11e4b736035e5f99f2831a57d0e2");
- try {
- text = Translate.execute(arg[3], Detect.execute(arg[1]), Detect.execute(arg[2]));
- } catch (Exception e) {
- sendError(channel, e);
- log(e + "");
- }
- sendMessage(channel, text);
- }
- // !debugvar - changes a variable to the value
- if (arg[0].equalsIgnoreCase(prefix + "debugvar")){
- if(checkPerm(sender, hostname, login)){
- switch(arg[1]){
- case "i": i = Integer.parseInt(arg[2]);
- sendMessage(channel, "DEBUG: Var \"i\" is now \"" + i + "\"");
- }
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- // !runcmd - Tells the bot to say run a OS command
- if (arg[0].equalsIgnoreCase(prefix + "runcmd")){
- if(checkPerm(sender, hostname, login)){
- String console;
- if(arg[1].equalsIgnoreCase("cmd") || arg[1].equalsIgnoreCase("command"))
- console = "cmd.exe";
- else if(arg[1].equalsIgnoreCase("term") || arg[1].equalsIgnoreCase("terminal"))
- console = "mintty.exe";
- else
- console = arg[1];
- ProcessBuilder builder = new ProcessBuilder(console);
- Process p=null;
- try {
- p = builder.start();
- }
- catch (IOException e) {
- sendError(channel, e);
- }
- //get stdin of shell
- BufferedWriter p_stdin = null;
- try {
- p_stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
- } catch (NullPointerException e) {
- sendMessage(channel, "error: " + e);
- }
- try {
- //single execution
- try {
- p_stdin.write(arg[2]);
- p_stdin.newLine();
- p_stdin.flush();
- } catch (NullPointerException e) {
- sendError(channel, e);
- }
- }
- catch (IOException e) {
- sendError(channel, e);
- }
- // finally close the shell by execution exit command
- try {
- p_stdin.write("exit");
- p_stdin.newLine();
- p_stdin.flush();
- }
- catch (IOException e) {
- sendError(channel, e);
- }
- // write stdout of shell (=output of all commands)
- Scanner s = null;
- try {
- s = new Scanner(p.getInputStream());
- } catch (Exception e) {
- sendMessage(channel, "error: " + e);
- }
- String output;
- int loop = i;
- if(console.equals("cmd.exe")){
- while(loop>0){
- try {
- s.nextLine();
- } catch (Exception e) {
- sendMessage(channel, "error: " + e);
- }
- loop--;
- }
- }
- while (s.hasNextLine())
- {
- output = s.nextLine();
- if(!output.contains("C:\\Users\\ggonz\\workspace\\MyBot")
- && !output.equals("Microsoft Windows [Version 10.0.10240]")
- && !output.equals("(c) 2015 Microsoft Corporation. All rights reserved.")
- && !output.contains("Directory of")
- && !output.contains("<DIR> .")
- && !output.contains("bytes free")
- && !output.contains("Volume in drive C is OS")
- && !output.contains("Volume Serial Number is")
- && !output.contains(">exit")){
- sendMessage(channel, output);
- }
- }
- s.close();
- }
- else {
- permError(sender, "can use this command");
- }
- }
- // !SayRaw - Tells the bot to send a raw line
- if (arg[0].equalsIgnoreCase(prefix + "SayRaw")){
- if(checkPerm(sender, hostname, login)){
- sendRawLineViaQueue(arg[1]);
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- // !SayNotice - Tells the bot to send a notice
- if (arg[0].equalsIgnoreCase(prefix + "SayNotice")){
- if(checkPerm(sender, hostname, login)){
- sendNotice(arg[1], arg[2]);
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- // !SayCTCPCommand - Tells the bot to send a CTCP Command
- if (arg[0].equalsIgnoreCase(prefix + "SayCTCPCommand")){
- if(checkPerm(sender, hostname, login)){
- sendCTCPCommand(arg[2], arg[1]);
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- //// !SayMethod - Tells the bot to run a method
- // if (arguments[0].equalsIgnoreCase(prefix + "sayMethod")){
- // if(checkPerm(sender, hostname, login)){
- // sendRawLineViaQueue(arguments[1]);
- // }
- // else {
- // permErrorchn(channel, sender, "can use this command");
- // }
- // }
- // !leave - Tells the bot to leave the current channel
- if (arg[0].equalsIgnoreCase(prefix + "leave")){
- if(checkPerm(sender, hostname, login)){
- partChannel(channel, "Successfully parted from " + channel);
- }
- else {
- permErrorchn(channel, sender, "can use this command");
- }
- }
- // !changenick - Changes the nick of the bot
- if (arg[0].equalsIgnoreCase(prefix + "changeNick")){
- if(checkPerm(sender, hostname, login)){
- changeNick(arg[1]);
- //sendMessage(channel, "Succsefully changed nick to " + arguments[1]);
- }
- else{
- permErrorchn(channel, sender , "can change the Nick of the bot");
- }
- }
- // !SayAction - Makes the bot do a action
- if (arg[0].equalsIgnoreCase(prefix + "SayAction")){
- if(checkPerm(sender, hostname, login)){
- sendAction(channel, arg[1]);
- }
- else{
- permErrorchn(channel, sender , "can make the bot do actions");
- }
- }
- // !QuitServ - Tells the bot to disconnect from server
- if (message.contentEquals(prefix + "quitserv")){
- if(checkPerm(sender, hostname, login)){
- sendNotice(sender, "Disconnecting from server");
- disconnect();
- System.exit(0);
- }
- else{
- permErrorchn(channel, sender , "can make the bot do actions");
- }
- }
- // !Spin has all of the Spin related sub commands
- if (arg[0].equalsIgnoreCase(prefix + "spin")){
- if (message.equalsIgnoreCase(prefix + "spin")){
- //sendMessage(channel,"DEBUG : Spin");
- }
- if (arg[1].equalsIgnoreCase("join")){
- if(playerList.contains(sender)){
- sendMessage(channel, sender + " :You are already in Spin.");
- }
- else{
- playerList.add(sender);
- sendMessage(channel, sender + " has joined spin");
- }
- }
- if (arg[1].equalsIgnoreCase("list")){
- sendMessage(channel,"Spin list is \"" + playerList.toString() + "\"");
- }
- if (arg[1].equalsIgnoreCase("clear")){
- playerList.clear();
- sendMessage(channel,"The Spin list has been cleared!");
- }
- if (arg[1].equalsIgnoreCase("help")){
- sendMessage(channel,"Spin is pretty much Russian Roulette. just join spin by typing in " + prefix + "spin join");
- }
- if (arg[1].equalsIgnoreCase("test")){
- sendMessage(channel,"DEBUG : Spin test");
- }
- }
- // !admin - Does admin commands
- if(arg[0].equalsIgnoreCase(prefix + "admin")){
- if(checkPerm(sender, hostname, login)){
- switch(arg[1].toLowerCase()){
- case "kick":
- if(arg.length <= 3){
- kick(channel, arg[2]);
- }
- else if(arg.length >= 3){
- kick(channel, arg[2], arg[3]);
- }
- break;
- case "op":
- op(channel, arg[2]);
- break;
- case "voice":
- voice(channel, arg[2]);
- break;
- case "deop":
- deOp(channel, arg[2]);
- break;
- case "devoice":
- deVoice(channel, arg[2]);
- break;
- }
- }
- else{
- permErrorchn(channel, sender, "can do admin commands with the bot");
- }
- }
- // !JokeCommands - toggle joke commands
- if (arg[0].equalsIgnoreCase(prefix + "JokeCommands")){
- if (message.equalsIgnoreCase(prefix + "JokeCommands")){
- if (jokeCommands){
- sendMessage(channel, "Joke commands are currently enabled");
- }
- else{
- sendMessage(channel, "Joke commands are currently disabled");
- }
- }
- if(arg[1].equalsIgnoreCase("toggle")){
- if(checkPerm(sender, hostname, login)){
- jokeCommands = !jokeCommands;
- if (jokeCommands){
- sendMessage(channel, "Joke commands are now enabled");
- }
- else{
- sendMessage(channel, "Joke commands are now disabled");
- }
- }
- else{
- permErrorchn(channel, sender , "can enable or disable the use of joke commands");
- }
- }
- }
- // !Splatoon - Joke command - ask the splatoon question
- if (message.equalsIgnoreCase(prefix + "Splatoon")){
- if(jokeCommands)
- sendMessage(channel, sender + ": YOU'RE A KID YOU'RE A SQUID");
- else
- sendMessage(channel, sender + ": Sorry, Joke commands are disabled");
- }
- // !attempt - Joke command - NOT ATTEMPTED
- if (message.equalsIgnoreCase(prefix + "attempt")){
- if(jokeCommands)
- sendMessage(channel, sender + ": NOT ATTEMPTED");
- else
- sendMessage(channel, sender + ": Sorry, Joke commands are disabled");
- }
- //// !stfu - Joke command - say "no u"
- // if (message.equalsIgnoreCase(prefix + "stfu")){
- // if(jokeCommands)
- // sendMessage(channel, sender + ": " + prefix + "no u");
- // }
- // !eatabowlofdicks - Joke command - joke help command
- if (message.equalsIgnoreCase(prefix + "eatabowlofdicks")){
- if(jokeCommands)
- sendMessage(channel, sender + ": " + "no u");
- }
- // !potato - Joke command - say "i am potato" in Japanese
- if (message.equalsIgnoreCase(prefix + "potato")){
- if(jokeCommands){
- byte[] bytes = "わたしわポタトデス".getBytes( Charset.forName("UTF-8"));
- String v = new String( bytes, Charset.forName("UTF-8") );
- sendMessage(channel, v);
- }
- else
- sendMessage(channel, sender + ": Sorry, Joke commands are disabled");
- }
- // !whatis? - Joke command -
- if (arg[0].equalsIgnoreCase(prefix + "whatis?")){
- if(jokeCommands){
- int num = randInt(0, dictionary.length - 1);
- String comeback = String.format(dictionary[num], arg[1]);
- sendMessage(channel, sender + comeback);
- }
- else
- sendMessage(channel, sender + ": Sorry, Joke commands are disabled");
- }
- // !getFinger - gets the Finger of the bot
- if (message.equalsIgnoreCase(prefix + "getFinger")){
- if(jokeCommands){
- sendMessage(channel, getFinger());
- }
- else
- sendMessage(channel, sender + ": Sorry, Joke commands are disabled");
- }
- }
- public void onNotice(String sourceNick, String sourceLogin, String sourceHostname, String target, String notice){
- List<String> argLog = splitMessage(notice);
- log(argLog.toString());
- String[] arg = argLog.toArray(new String[argLog.size()]);
- if(target.equals(getNick()))
- sendNotice(currentNick, "Notice from " + sourceNick + " in " + sourceNick + ". Notice was :" + notice);
- }
- // public void onJoin(String channel, String sender, String login, String hostname){
- // sendNotice(sender, "\u0001AVATAR http://puu.sh/kA75A.jpg 19117\u0001");
- // }
- public void onPrivateMessage(String sender, String login, String hostname, String message)
- {
- List<String> argLog = splitMessage(message);
- log(argLog.toString());
- String[] arg = argLog.toArray(new String[argLog.size()]);
- if (message.equals("\u0001AVATAR\u0001")){
- sendNotice(sender, "\u0001AVATAR http://puu.sh/kA75A.jpg 19117\u0001");
- }
- if (message.equals("\u0001")){
- sendNotice(sender, "\u0001AVATAR http://puu.sh/kA75A.jpg 19117\u0001");
- }
- // !login - Sets the authed named to the new name ...if the password is right
- if (arg[0].equalsIgnoreCase(prefix + "login")){
- if(arg[1].equals(PASSWORD)){
- currentNick = sender;
- currentUsername = login;
- }
- else
- sendMessage(sender, "password is incorrect.");
- }
- //Only allow me (Lil-G) to use PM commands except for the login command
- else if(checkPerm(sender, hostname, login) && !arg[0].equalsIgnoreCase(prefix + "login") && arg[0].contains(prefix)){
- // !SendTo - Tells the bot to say someting on a channel
- if (arg[0].equalsIgnoreCase(prefix + "sendto")){
- sendMessage(arg[1], arg[2]);
- }
- // !SayAction - Tells the bot to make a action on a channel
- if (arg[0].equalsIgnoreCase(prefix + "SayAction")){
- sendAction(arg[1], arg[2]);
- }
- // !changenick- Changes the nick of the bot
- if (arg[0].equalsIgnoreCase(prefix + "changeNick")){
- changeNick(arg[1]);
- sendNotice(sender, "Succsefully changed nick to " + arg[1]);
- }
- // !Connect - Tells the bot to connect to specified channel
- if (arg[0].equalsIgnoreCase(prefix + "connect")){
- joinChannel(arg[1]);
- sendNotice(sender, "Succsefully connected to " + arg[1]);
- }
- // !Exit - Tells the bot to disconnect from specified channel
- if (arg[0].equalsIgnoreCase(prefix + "exit")){
- partChannel(arg[1], "Successfully parted from " + arg[1]);
- }
- // !QuitServ - Tells the bot to disconnect from server
- if (message.equalsIgnoreCase(prefix + "quitserv")){
- sendNotice(sender, "Disconnecting from server");
- disconnect();
- System.exit(0);
- }
- }
- else if(arg[0].startsWith(prefix)) {
- permError(sender, "can use PM commands");
- sendMessage(currentNick, "Attempted use of PM commands by " + sender + ". The command used was \"" + message + "\"");
- }
- }
- public void onOp(String channel, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
- {
- if(recipient.equals(getNick()))
- sendNotice(currentNick, "i have been given OP from " + sourceNick + " in " + channel);
- }
- public void onVoice(String channel, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
- {
- if(recipient.equals(getNick()))
- sendNotice(currentNick, "i have been given Voice from " + sourceNick + " in " + channel);
- }
- public void onPing(String channel, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
- {
- if(recipient.equals(getNick()))
- sendNotice(currentNick, "Ping from " + sourceNick + " in " + channel);
- }
- public void onDisconnect(){
- while (!isConnected()) {
- try {
- TimeUnit.SECONDS.sleep(3);
- reconnect();
- }
- catch (Exception e) {
- // Couldn't reconnect!
- // Pause for a short while...?
- }
- }
- }
- public void onKick(String channel, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason){
- if (recipientNick.equalsIgnoreCase(getNick())) {
- try {
- TimeUnit.SECONDS.sleep(3);
- } catch (InterruptedException e) {
- System.out.print(e);
- }
- joinChannel(channel);
- }
- }
- public void onNickChange(String oldNick, String login, String hostname, String newNick){
- if(newNick.equalsIgnoreCase(currentNick)){
- currentNick = null;
- }
- if(oldNick.equalsIgnoreCase(currentNick)){
- currentNick = newNick;
- }
- }
- /**
- * Returns a pseudo-random number between min and max, inclusive.
- * The difference between min and max can be at most
- * <code>Integer.MAX_VALUE - 1</code>.
- *
- * @param min Minimum value
- * @param max Maximum value. Must be greater than min.
- * @return Integer between min and max, inclusive.
- * @see java.util.Random#nextInt(int)
- */
- public static int randInt(int min, int max) {
- // NOTE: Usually this should be a field rather than a method
- // variable so that it is not re-seeded every call.
- Random rand = new Random();
- // nextInt is normally exclusive of the top value,
- // so add 1 to make it inclusive
- return rand.nextInt((max - min) + 1) + min;
- }
- /**
- * tells the user they don't have permission to use the command
- *
- * @param sender User trying to use command
- * @param e String to send back
- */
- public void permError(String sender, String e){
- sendNotice(sender, ": Sorry, only Lil-G " + e);
- }
- /**
- * same as permError() except to be used in channels
- *
- * @param channel Channel that the user used the command in
- * @param sender User trying to use command
- * @param e String to send back
- */
- public void permErrorchn(String channel, String sender, String e){ sendMessage(channel, sender + ": Sorry, only Lil-G " + e); }
- /**
- * Checks if the user attempting to use the command is allowed
- *
- * @param sender User trying to use command
- * @param hostname hostname of user trying to use command
- * @return Boolean true if allowed, false if not
- */
- public boolean checkPerm(String sender, String hostname, String login){
- log("attempted use of command by "+ sender + "!" + login + "@" + hostname);
- if(sender.equalsIgnoreCase(currentNick) && login.equalsIgnoreCase(currentUsername)){
- return true;
- }
- else{
- log("user " + sender + " was denied");
- return false;
- }
- }
- private List<String> splitMessage(String s) {
- if (s == null)
- return Collections.emptyList();
- List<String> list = new ArrayList<String>();
- Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(s);
- while (m.find())
- list.add(m.group(1)); // Add .replace("\"", "") to remove surrounding quotes.
- int i = 0;
- while(list.size() > i){
- list.set(i, list.get(i).replaceAll("\"", ""));
- i++;
- }
- return list;
- }
- public static String getBytes(String bytes){
- byte[] Bytes = bytes.getBytes();
- return Arrays.toString(Bytes);
- }
- public static String formatFileSize(long size) {
- String hrSize = null;
- double b = size;
- double k = size/1024.0;
- double m = ((size/1024.0)/1024.0);
- double g = (((size/1024.0)/1024.0)/1024.0);
- double t = ((((size/1024.0)/1024.0)/1024.0)/1024.0);
- DecimalFormat dec = new DecimalFormat("0.00");
- if ( t>1 ) {
- hrSize = dec.format(t).concat(" TB");
- } else if ( g>1 ) {
- hrSize = dec.format(g).concat(" GB");
- } else if ( m>1 ) {
- hrSize = dec.format(m).concat(" MB");
- } else if ( k>1 ) {
- hrSize = dec.format(k).concat(" KB");
- } else {
- hrSize = dec.format(b).concat(" Bytes");
- }
- return hrSize;
- }
- public String botTalk(String bot, String message) throws Exception{
- if(bot.equalsIgnoreCase("clever")){
- return cleverBotsession.think(message);
- }
- else if(bot.equalsIgnoreCase("pandora")){
- return pandoraBotsession.think(message);
- }
- else{
- return "Error, not a valid bot";
- }
- }
- public int findIn(String[] list, String nick){
- int index = 0;
- int max = list.length;
- boolean found = false;
- while(!found && index == max){
- index++;
- if(list[index].equalsIgnoreCase(nick)){
- found = true;
- }
- }
- return index;
- }
- public int findIn(User[] list, String nick){
- int index = 0;
- int max = list.length;
- boolean found = false;
- while(!found && index == max){
- index++;
- if(list[index].equals(nick.toLowerCase())){
- found = true;
- }
- }
- return index;
- }
- public void log(String line) {
- if (getVerbose()) {
- System.out.println(System.currentTimeMillis() + " " + line);
- }
- if (line.startsWith("@## ")){
- String str = line.substring(4);
- if (!(str.equalsIgnoreCase("java.util.NoSuchElementException") || str.equalsIgnoreCase("\tat java.util.StringTokenizer.nextToken(StringTokenizer.java:349)") || str.equalsIgnoreCase("\tat org.jibble.pircbot.PircBot.handleLine(PircBot.java:891)") || str.equalsIgnoreCase("\tat org.jibble.pircbot.InputThread.run(InputThread.java:92)"))) {
- sendNotice(currentNick, str);
- }
- }
- }
- public void sendError(String Channel, Exception e){
- sendMessage(Channel, "Error: " + e);
- }
- public void setDebugMode(boolean debugMode) {
- this.debugMode = debugMode;
- }
- }
Add Comment
Please, Sign In to add comment