Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.95 KB | None | 0 0
  1. import org.jibble.pircbot.*;
  2. import java.io.BufferedWriter;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.io.FileReader;
  6. import java.io.BufferedReader;
  7. import java.lang.String;
  8. import java.io.InputStreamReader;
  9. import java.io.*;
  10.  
  11. public class MyBot extends PircBot {
  12. static GUI currentGUI = new GUI();
  13. String banName = "";
  14. boolean Ban = false;
  15. boolean delBan = false;
  16. String banChannel = "";
  17.  
  18. public MyBot() {
  19. currentGUI.ShowComponents();
  20. this.setName("CynoBot");
  21. }
  22.  
  23. public String clamp(String command) {
  24. String line1 = "";
  25. try {
  26. String line;
  27. Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /" + command);
  28. BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
  29. while ((line = input.readLine()) != null) {
  30. line1 = line;
  31. }
  32. input.close();
  33. } catch(IOException e) {
  34. }
  35. return line1;
  36. }
  37.  
  38. public int countLines(String filename) throws IOException {
  39. InputStream is = new BufferedInputStream(new FileInputStream(filename));
  40. try {
  41. byte[] c = new byte[1024];
  42. int count = 0;
  43. int readChars = 0;
  44. while ((readChars = is.read(c)) != -1) {
  45. for (int i = 0; i < readChars; ++i) {
  46. if (c[i] == '\n')
  47. ++count;
  48. }
  49. }
  50. return count;
  51. } finally {
  52. is.close();
  53. }
  54. }
  55.  
  56.  
  57.  
  58. @Override
  59. public void log(String line) {
  60. currentGUI.ChatLog.append(line + "\n");
  61. currentGUI.ChatLog.setCaretPosition(currentGUI.ChatLog.getText().length());
  62. }
  63.  
  64. public boolean HasRated(String name, String song) {
  65. boolean lulz = false;
  66. try {
  67. BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
  68. String str;
  69. while ((str = in.readLine()) != null) {
  70. if(lulz){
  71. break;
  72. }
  73. String[] Awef = str.split("/");
  74. if(Awef[0].equalsIgnoreCase(name)) {
  75. for (int b = 0; b<Awef.length; b++) {
  76. if(Awef[b].equalsIgnoreCase(song)){
  77. lulz = true;
  78. break;
  79. } else {
  80. lulz = false;
  81. }
  82. }
  83. }
  84. }
  85. in.close();
  86. } catch (IOException e) {
  87. }
  88. return lulz;
  89. }
  90.  
  91. public boolean StoreRate(String name, String song) {
  92. String str;
  93. String str2 = "";
  94. int b = 0;
  95. String[][] store;
  96. String[] store2;
  97.  
  98. if(!HasRated(name, song)){
  99.  
  100. try {
  101.  
  102. store = new String[countLines("Ratings.txt")][Integer.parseInt(clamp("PLINFO LENGTH"))];
  103. store2 = new String[countLines("Ratings.txt")];
  104. BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
  105.  
  106. while ((str = in.readLine()) != null) {
  107. String[] Awef = str.split("/");
  108. store2[b] = Awef[0];
  109. if(Awef[0].equalsIgnoreCase(name)) {
  110. for(int i=0; i>Awef.length-1; i++){
  111. store[b][i] = Awef[i+1];
  112. }
  113. }
  114. b++;
  115. }
  116. for(int u=0; u>store2.length; u++){
  117. str2 = str2 + store2[u];
  118. for(int h=0; h>store[u].length; h++){
  119. str2 = str2 + store[u][h] + '/';
  120. }
  121. str2 = str2 + '\n';
  122. }
  123.  
  124. BufferedWriter out = new BufferedWriter(new FileWriter("Ratings.txt"));
  125. out.write(str2);
  126. out.close();
  127. in.close();
  128.  
  129. } catch (IOException e) {
  130. }
  131. }
  132. return true;
  133. }
  134.  
  135. public void onJoin(String channel, String sender, String login, String hostname) {
  136. try {
  137.  
  138. BufferedReader in = new BufferedReader(new FileReader("BanListMasks.txt"));
  139. String str;
  140. while ((str = in.readLine()) != null) {
  141. System.out.println(str);
  142. if(str.equalsIgnoreCase(hostname + '\n') || str.equalsIgnoreCase(hostname)){
  143. banName = sender;
  144. Ban = true;
  145. sendRawLine("WHOIS " + sender);
  146. banChannel = channel;
  147. kick(channel, sender, "Kicked-banned by: Auto-KB for ban evasion.");
  148. }
  149. }
  150.  
  151. BufferedReader in2 = new BufferedReader(new FileReader("BanListNames.txt"));
  152. String str2;
  153. while ((str2 = in2.readLine()) != null) {
  154. System.out.println(str2);
  155. if(str2.equalsIgnoreCase(sender + '\n') || str2.equalsIgnoreCase(sender)){
  156. banName = sender;
  157. Ban = true;
  158. sendRawLine("WHOIS " + sender);
  159. banChannel = channel;
  160. kick(channel, sender, "Kicked-banned by: Auto-KB for ban evasion.");
  161. }
  162. }
  163.  
  164. } catch (IOException e) {
  165. }
  166. }
  167.  
  168. public void onServerResponse(int code, String response) {
  169. String[] Whois = response.split(" ");
  170.  
  171. if(Ban){
  172. if(Whois[5].charAt(0) == ':' && Whois[1].equalsIgnoreCase(banName)){
  173. System.out.println("Banned via /whois command. " + banName + " " + Whois[2] + "@" + Whois[3]);
  174. try {
  175. ban(banChannel, Whois[3]);
  176.  
  177. BufferedReader in = new BufferedReader(new FileReader("BanListMasks.txt"));
  178. String str;
  179. String str2 = "";
  180. while ((str = in.readLine()) != null) {
  181. if(!str.equalsIgnoreCase(Whois[3]) && !str.equalsIgnoreCase(Whois[3] + '\n')){
  182. str2 = str + '\n' + str2;
  183. } else {
  184. Ban = false;
  185. }
  186. }
  187.  
  188. BufferedReader in2 = new BufferedReader(new FileReader("BanListNames.txt"));
  189. String str3;
  190. String str4 = "";
  191. while ((str3 = in2.readLine()) != null) {
  192. if(!str3.equalsIgnoreCase(banName) && !str3.equalsIgnoreCase(banName + '\n')){
  193. str4 = str3 + '\n' + str4;
  194. } else {
  195. Ban = false;
  196. }
  197. }
  198. if(Ban){
  199. BufferedWriter out = new BufferedWriter(new FileWriter("BanListMasks.txt"));
  200. out.write(str2 + Whois[3]+ '\n');
  201. out.close();
  202.  
  203. BufferedWriter out2 = new BufferedWriter(new FileWriter("BanListNames.txt"));
  204. out2.write(str4 + banName + '\n');
  205. out2.close();
  206.  
  207. Ban = false;
  208. }
  209. } catch (IOException e) {
  210. }
  211. }
  212. } else {
  213.  
  214. if(delBan){
  215. if(Whois[5].charAt(0) == ':'){
  216. unBan(banChannel, Whois[3]);
  217. delBan = false;
  218. }
  219. }
  220.  
  221. }
  222. }
  223.  
  224. public void onPrivateMessage(String sender, String login, String hostname, String message) {
  225. log("PM from" + sender + ": " + message);
  226. String[] Args = message.split(" ");
  227. if(message.charAt(0) == '!'){
  228.  
  229. boolean admin = false;
  230.  
  231. try {
  232. BufferedReader in = new BufferedReader(new FileReader("AdminList.txt"));
  233. String str;
  234. while ((str = in.readLine()) != null) {
  235. if(sender.equalsIgnoreCase(str)) {
  236. if (!admin) {
  237. admin = true;
  238. break;
  239. }
  240. }
  241. }
  242. in.close();
  243. } catch (IOException e) {
  244. }
  245.  
  246. if(admin) {
  247.  
  248. if (Args[0].equalsIgnoreCase("!join")|Args[0].equalsIgnoreCase("!j")) {
  249. joinChannel(Args[1]);
  250. }
  251.  
  252. if (Args[0].equalsIgnoreCase("!part")|Args[0].equalsIgnoreCase("!p")) {
  253. if(Args[1] == ""){
  254. } else {
  255. partChannel(Args[1]);
  256. }
  257. }
  258.  
  259. if (Args[0].equalsIgnoreCase("!dc")) {
  260. disconnect();
  261. }
  262.  
  263. }
  264. }
  265. }
  266.  
  267. public void onMessage(String channel, String sender,
  268. String login, String hostname, String message) {
  269. log(channel + ": " + message);
  270. String[] Args = message.split(" ");
  271.  
  272. if(message.charAt(0) == '!'){
  273.  
  274. boolean admin = false;
  275.  
  276. try {
  277. BufferedReader in = new BufferedReader(new FileReader("AdminList.txt"));
  278. String str;
  279. while ((str = in.readLine()) != null) {
  280. if(sender.equalsIgnoreCase(str)) {
  281. if (!admin) {
  282. admin = true;
  283. break;
  284. }
  285. }
  286. }
  287. in.close();
  288. } catch (IOException e) {
  289. }
  290.  
  291. if(admin) {
  292.  
  293. if (Args[0].equalsIgnoreCase("!join")|Args[0].equalsIgnoreCase("!j")) {
  294. joinChannel(Args[1]);
  295. }
  296.  
  297. if (Args[0].equalsIgnoreCase("!part")|Args[0].equalsIgnoreCase("!p")) {
  298. try
  299. {
  300. if(Args[1].equalsIgnoreCase("") || Args[1].equalsIgnoreCase(" ")){
  301. } else {
  302. partChannel(Args[1]);
  303. }
  304. }
  305. catch (ArrayIndexOutOfBoundsException ex) {
  306. partChannel(channel);
  307. }
  308. }
  309.  
  310. if (Args[0].equalsIgnoreCase("!kb")) {
  311. banName = Args[1];
  312. Ban = true;
  313. sendRawLine("WHOIS " + Args[1]);
  314. banChannel = channel;
  315. kick(channel, Args[1], "Kicked-banned by: " + sender);
  316. }
  317.  
  318. if (Args[0].equalsIgnoreCase("!kick")) {
  319. kick(channel, Args[1], "Kicked by: " + sender);
  320. }
  321.  
  322. if (Args[0].equalsIgnoreCase("!dc")) {
  323. disconnect();
  324. }
  325.  
  326. if (Args[0].equalsIgnoreCase("!ban")) {
  327. banName = Args[1];
  328. Ban = true;
  329. banChannel = channel;
  330. sendRawLine("WHOIS " + Args[1]);
  331. }
  332.  
  333. if (Args[0].equalsIgnoreCase("!unban")) {
  334. banChannel = channel;
  335. banName = Args[1];
  336. delBan = true;
  337. sendRawLine("WHOIS " + Args[1]);
  338. }
  339.  
  340. }
  341.  
  342. if (Args[0].equalsIgnoreCase("!song")) {
  343. try {
  344. String line;
  345. Integer U = 0;
  346. Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE /POS");
  347. BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
  348. String line1 = "Song: ";
  349. while ((line = input.readLine()) != null) {
  350. if (U == 0) {
  351. line1 = line1 + line + " Length: ";
  352. } else {
  353. line1 = line1 + line;
  354. }
  355. U++;
  356. }
  357. sendMessage(sender, line1);
  358. input.close();
  359. } catch (Exception err) {
  360. err.printStackTrace();
  361. }
  362. }
  363.  
  364. if (Args[0].equalsIgnoreCase("!rating")) {
  365. String title = "Song: ";
  366. try {
  367. String line;
  368. Integer i = 0;
  369. Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE /RATING");
  370. BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
  371. while ((line = input.readLine()) != null) {
  372. if (i == 0) {
  373. title = title + line + " Rating: ";
  374. } else {
  375. title = title + line;
  376. }
  377. i++;
  378. }
  379. sendMessage(sender, title);
  380. input.close();
  381. } catch (Exception err) {
  382. err.printStackTrace();
  383. }
  384. }
  385.  
  386. if (Args[0].equalsIgnoreCase("!rate")) {
  387. String line1 = "";
  388. try {
  389. Process song = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /TITLE");
  390. BufferedReader song2 = new BufferedReader(new InputStreamReader(song.getInputStream()));
  391. String line;
  392. while ((line = song2.readLine()) != null) {
  393. line1 = line;
  394. System.out.println("Song: " + line1);
  395. }
  396. if(!HasRated(sender, line1)) {
  397. String line3;
  398. Process p = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /RATING");
  399. BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
  400. Integer line2 = 0;
  401. while ((line3 = input.readLine()) != null) {
  402. if(Integer.parseInt(Args[1]) >= 5) {
  403. line2 = Integer.parseInt(line3) + 1;
  404. StoreRate(sender, line1);
  405. } else {
  406. line2 = Integer.parseInt(line3) - 1;
  407. StoreRate(sender, line1);
  408. }
  409. }
  410. input.close();
  411. Process c = Runtime.getRuntime().exec("C:\\mybot\\CLAmp.exe /RATING=" + line2);
  412. }
  413. } catch (Exception err) {
  414. err.printStackTrace();
  415. }
  416. }
  417.  
  418. }
  419. }
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement