Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.jibble.pircbot.*;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.FileReader;
- import java.io.BufferedReader;
- import java.lang.String;
- import java.io.InputStreamReader;
- import java.io.*;
- public class MyBot extends PircBot {
- static GUI currentGUI = new GUI();
- String banName = "";
- boolean Ban = false;
- boolean delBan = false;
- String banChannel = "";
- public MyBot() {
- currentGUI.ShowComponents();
- this.setName("CynoBot");
- }
- public String clamp(String command) {
- String line1 = "";
- try {
- String line;
- Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /" + command);
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- while ((line = input.readLine()) != null) {
- line1 = line;
- }
- input.close();
- } catch(IOException e) {
- }
- return line1;
- }
- public int countLines(String filename) throws IOException {
- InputStream is = new BufferedInputStream(new FileInputStream(filename));
- try {
- byte[] c = new byte[1024];
- int count = 0;
- int readChars = 0;
- while ((readChars = is.read(c)) != -1) {
- for (int i = 0; i < readChars; ++i) {
- if (c[i] == '\n')
- ++count;
- }
- }
- return count;
- } finally {
- is.close();
- }
- }
- @Override
- public void log(String line) {
- currentGUI.ChatLog.append(line + "\n");
- currentGUI.ChatLog.setCaretPosition(currentGUI.ChatLog.getText().length());
- }
- public boolean HasRated(String name, String song) {
- boolean lulz = false;
- try {
- BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
- String str;
- while ((str = in.readLine()) != null) {
- if(lulz){
- break;
- }
- String[] Awef = str.split("/");
- if(Awef[0].equalsIgnoreCase(name)) {
- for (int b = 0; b<Awef.length; b++) {
- if(Awef[b].equalsIgnoreCase(song)){
- lulz = true;
- break;
- } else {
- lulz = false;
- }
- }
- }
- }
- in.close();
- } catch (IOException e) {
- }
- return lulz;
- }
- public boolean StoreRate(String name, String song) {
- String str;
- String str2 = "";
- int b = 0;
- String[][] store;
- String[] store2;
- if(!HasRated(name, song)){
- try {
- store = new String[countLines("Ratings.txt")][Integer.parseInt(clamp("PLINFO LENGTH"))];
- store2 = new String[countLines("Ratings.txt")];
- BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
- while ((str = in.readLine()) != null) {
- String[] Awef = str.split("/");
- store2[b] = Awef[0];
- if(Awef[0].equalsIgnoreCase(name)) {
- for(int i=0; i>Awef.length-1; i++){
- store[b][i] = Awef[i+1];
- }
- }
- b++;
- }
- for(int u=0; u>store2.length; u++){
- str2 = str2 + store2[u];
- for(int h=0; h>store[u].length; h++){
- str2 = str2 + store[u][h] + '/';
- }
- str2 = str2 + '\n';
- }
- BufferedWriter out = new BufferedWriter(new FileWriter("Ratings.txt"));
- out.write(str2);
- out.close();
- in.close();
- } catch (IOException e) {
- }
- }
- return true;
- }
- public void onJoin(String channel, String sender, String login, String hostname) {
- try {
- BufferedReader in = new BufferedReader(new FileReader("BanListMasks.txt"));
- String str;
- while ((str = in.readLine()) != null) {
- System.out.println(str);
- if(str.equalsIgnoreCase(hostname + '\n') || str.equalsIgnoreCase(hostname)){
- banName = sender;
- Ban = true;
- sendRawLine("WHOIS " + sender);
- banChannel = channel;
- kick(channel, sender, "Kicked-banned by: Auto-KB for ban evasion.");
- }
- }
- BufferedReader in2 = new BufferedReader(new FileReader("BanListNames.txt"));
- String str2;
- while ((str2 = in2.readLine()) != null) {
- System.out.println(str2);
- if(str2.equalsIgnoreCase(sender + '\n') || str2.equalsIgnoreCase(sender)){
- banName = sender;
- Ban = true;
- sendRawLine("WHOIS " + sender);
- banChannel = channel;
- kick(channel, sender, "Kicked-banned by: Auto-KB for ban evasion.");
- }
- }
- } catch (IOException e) {
- }
- }
- public void onServerResponse(int code, String response) {
- String[] Whois = response.split(" ");
- if(Ban){
- if(Whois[5].charAt(0) == ':' && Whois[1].equalsIgnoreCase(banName)){
- System.out.println("Banned via /whois command. " + banName + " " + Whois[2] + "@" + Whois[3]);
- try {
- ban(banChannel, Whois[3]);
- BufferedReader in = new BufferedReader(new FileReader("BanListMasks.txt"));
- String str;
- String str2 = "";
- while ((str = in.readLine()) != null) {
- if(!str.equalsIgnoreCase(Whois[3]) && !str.equalsIgnoreCase(Whois[3] + '\n')){
- str2 = str + '\n' + str2;
- } else {
- Ban = false;
- }
- }
- BufferedReader in2 = new BufferedReader(new FileReader("BanListNames.txt"));
- String str3;
- String str4 = "";
- while ((str3 = in2.readLine()) != null) {
- if(!str3.equalsIgnoreCase(banName) && !str3.equalsIgnoreCase(banName + '\n')){
- str4 = str3 + '\n' + str4;
- } else {
- Ban = false;
- }
- }
- if(Ban){
- BufferedWriter out = new BufferedWriter(new FileWriter("BanListMasks.txt"));
- out.write(str2 + Whois[3]+ '\n');
- out.close();
- BufferedWriter out2 = new BufferedWriter(new FileWriter("BanListNames.txt"));
- out2.write(str4 + banName + '\n');
- out2.close();
- Ban = false;
- }
- } catch (IOException e) {
- }
- }
- } else {
- if(delBan){
- if(Whois[5].charAt(0) == ':'){
- unBan(banChannel, Whois[3]);
- delBan = false;
- }
- }
- }
- }
- public void onPrivateMessage(String sender, String login, String hostname, String message) {
- log("PM from" + sender + ": " + message);
- String[] Args = message.split(" ");
- if(message.charAt(0) == '!'){
- boolean admin = false;
- try {
- BufferedReader in = new BufferedReader(new FileReader("AdminList.txt"));
- String str;
- while ((str = in.readLine()) != null) {
- if(sender.equalsIgnoreCase(str)) {
- if (!admin) {
- admin = true;
- break;
- }
- }
- }
- in.close();
- } catch (IOException e) {
- }
- if(admin) {
- if (Args[0].equalsIgnoreCase("!join")|Args[0].equalsIgnoreCase("!j")) {
- joinChannel(Args[1]);
- }
- if (Args[0].equalsIgnoreCase("!part")|Args[0].equalsIgnoreCase("!p")) {
- if(Args[1] == ""){
- } else {
- partChannel(Args[1]);
- }
- }
- if (Args[0].equalsIgnoreCase("!dc")) {
- disconnect();
- }
- }
- }
- }
- public void onMessage(String channel, String sender,
- String login, String hostname, String message) {
- log(channel + ": " + message);
- String[] Args = message.split(" ");
- if(message.charAt(0) == '!'){
- boolean admin = false;
- try {
- BufferedReader in = new BufferedReader(new FileReader("AdminList.txt"));
- String str;
- while ((str = in.readLine()) != null) {
- if(sender.equalsIgnoreCase(str)) {
- if (!admin) {
- admin = true;
- break;
- }
- }
- }
- in.close();
- } catch (IOException e) {
- }
- if(admin) {
- if (Args[0].equalsIgnoreCase("!join")|Args[0].equalsIgnoreCase("!j")) {
- joinChannel(Args[1]);
- }
- if (Args[0].equalsIgnoreCase("!part")|Args[0].equalsIgnoreCase("!p")) {
- try
- {
- if(Args[1].equalsIgnoreCase("") || Args[1].equalsIgnoreCase(" ")){
- } else {
- partChannel(Args[1]);
- }
- }
- catch (ArrayIndexOutOfBoundsException ex) {
- partChannel(channel);
- }
- }
- if (Args[0].equalsIgnoreCase("!kb")) {
- banName = Args[1];
- Ban = true;
- sendRawLine("WHOIS " + Args[1]);
- banChannel = channel;
- kick(channel, Args[1], "Kicked-banned by: " + sender);
- }
- if (Args[0].equalsIgnoreCase("!kick")) {
- kick(channel, Args[1], "Kicked by: " + sender);
- }
- if (Args[0].equalsIgnoreCase("!dc")) {
- disconnect();
- }
- if (Args[0].equalsIgnoreCase("!ban")) {
- banName = Args[1];
- Ban = true;
- banChannel = channel;
- sendRawLine("WHOIS " + Args[1]);
- }
- if (Args[0].equalsIgnoreCase("!unban")) {
- banChannel = channel;
- banName = Args[1];
- delBan = true;
- sendRawLine("WHOIS " + Args[1]);
- }
- }
- if (Args[0].equalsIgnoreCase("!song")) {
- try {
- String line;
- Integer U = 0;
- Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE /POS");
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line1 = "Song: ";
- while ((line = input.readLine()) != null) {
- if (U == 0) {
- line1 = line1 + line + " Length: ";
- } else {
- line1 = line1 + line;
- }
- U++;
- }
- sendMessage(sender, line1);
- input.close();
- } catch (Exception err) {
- err.printStackTrace();
- }
- }
- if (Args[0].equalsIgnoreCase("!rating")) {
- String title = "Song: ";
- try {
- String line;
- Integer i = 0;
- Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE /RATING");
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- while ((line = input.readLine()) != null) {
- if (i == 0) {
- title = title + line + " Rating: ";
- } else {
- title = title + line;
- }
- i++;
- }
- sendMessage(sender, title);
- input.close();
- } catch (Exception err) {
- err.printStackTrace();
- }
- }
- if (Args[0].equalsIgnoreCase("!rate")) {
- String line1 = "";
- try {
- Process song = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE");
- BufferedReader song2 = new BufferedReader(new InputStreamReader(song.getInputStream()));
- String line;
- while ((line = song2.readLine()) != null) {
- line1 = line;
- System.out.println("Song: " + line1);
- }
- if(!HasRated(sender, line1)) {
- String line3;
- Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /RATING");
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- Integer line2 = 0;
- while ((line3 = input.readLine()) != null) {
- if(Integer.parseInt(Args[1]) >= 5) {
- line2 = Integer.parseInt(line3) + 1;
- StoreRate(sender, line1);
- } else {
- line2 = Integer.parseInt(line3) - 1;
- StoreRate(sender, line1);
- }
- }
- input.close();
- Process c = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /RATING=" + line2);
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement