Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. package com.vivabenfica4ps3.gmail;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.InputStream;
  5. import java.util.Collection;
  6. import java.util.Map;
  7. import java.util.Scanner;
  8.  
  9. import org.ho.yaml.Yaml;
  10. import org.jibble.pircbot.*;
  11.  
  12. public class ToddBot extends PircBot
  13. {
  14.  
  15. private String channel = "#anotherfail";
  16. private boolean hangman = false;
  17. private String hangmanword = "";
  18. private String word = "";
  19. private String sender;
  20. private boolean wordIsCreated = false;
  21. private boolean wordIsChosen = false;
  22. StringBuilder wordSolve;
  23. Thread wordCreation = new Thread(){
  24.  
  25. @Override
  26. public void run() {
  27. if(wordIsCreated = true){
  28. System.out.println("The word is: " + word);
  29. wordSolve = new StringBuilder(word);
  30. sendMessage(channel, "[HANGMAN] The word is " + wordSolve);
  31. wordIsChosen = true;
  32. }
  33. else{
  34. sendMessage(channel, "No word has been selected. Game Cancelled");
  35. }
  36. }
  37.  
  38. };;
  39.  
  40. public ToddBot(String username) {
  41. this.setName(username);
  42. }
  43.  
  44. public void test(){
  45. System.out.println("This Worked!");
  46. }
  47.  
  48. @Override
  49. public void onMessage(String channel, String sender, String login, String hostname, String message) {
  50. String responce;
  51. boolean commandIsSaid = true;
  52. switch(message){
  53. case "!info": responce = "Hi, my name is TodButler and I am ToddAwesome's new personal assistant created by SecondAmendmentHD! for a List of commands type !commands";
  54. break;
  55. case "!commands": responce = "Current Commands: !info, !donate, !hangman, !rules, !commands";
  56. break;
  57. case "!donate": responce = "If you are feeling generous today and would like to send me a donation click on the Donate Icon below!";
  58. break;
  59. case "!hangman": responce = "has started a hangman game! Guess letters to enter or the whole word!"; if(!hangman && !wordIsCreated && !wordIsChosen)startHangman(sender);
  60. break;
  61. case "!rules": responce = "Be Friendly, Polite and Respectful - Do not Instigate or Encourage Hateful Conversation - Do not ask FOR/WHEN the giveaways -Don't Spam - English Only - No Advertising - and Lastly, Stay Awesome!";
  62. break;
  63. default: responce = ""; commandIsSaid = false;
  64. break;
  65. }
  66. if(commandIsSaid){
  67. if(message.equals("!hangman") && hangman && wordIsCreated && wordIsChosen){
  68. sendMessage(channel, "@" + sender + " There is currently a hangman in progress.");
  69. }
  70. else{
  71. sendMessage(channel, "@" + sender + " " + responce);
  72. }
  73. }
  74.  
  75. if(hangman == true){
  76. if(hangmanword.contains(message.toUpperCase()) && message.length() == 1){
  77. for(int x = 0; x <= (hangmanword.length()-1); x++){
  78. if(hangmanword.substring(x, x+1).equals(message.toUpperCase())){
  79. wordSolve.setCharAt(x * 2, message.toUpperCase().charAt(0));
  80. }
  81. }
  82. if(wordSolve.toString().trim().equals(hangmanword.replace("", " ").trim())){
  83. sendMessage(channel, sender + " has guessed the final letter, the word is " + hangmanword + " Congratulations @" + sender); hangman = false; word = ""; wordIsCreated = false; wordIsChosen = false;
  84. }
  85. else if(wordSolve != null && wordSolve.toString().equals(message.replace("", " ").trim())){sendMessage(channel, sender + " has guessed the word, the word is " + hangmanword + " Congratulations @" + sender); hangman = false; word = ""; wordIsCreated = false; wordIsChosen = false;}
  86. else sendMessage(channel, "@" + sender + " has guessed a letter, word is now: " + wordSolve);
  87. }
  88. }
  89. }
  90.  
  91. public void parseYaml(){
  92. final String fileName = "C:/Users/Samuel/Desktop/Commands.yml";
  93. Yaml yaml = new Yaml();
  94.  
  95. try {
  96. InputStream ios = new FileInputStream(new File(fileName));
  97.  
  98. // Parse the YAML file and return the output as a series of Maps and Lists
  99. Map<String,Object> command = (Map<String,Object>)yaml.load(ios);
  100. Collection<Object> responce = command.values();
  101.  
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. }
  105. }
  106.  
  107. @Override
  108. public void onUnknown(String line){
  109. if(line.contains(":" + sender + "!" + sender + "@" + sender + ".tmi.twitch.tv WHISPER toddbutler :")){
  110. String message = line.substring(line.lastIndexOf(" :") + 2);
  111. hangmanword = message.toUpperCase();
  112. System.out.println(message);
  113. if(hangman == true && this.sender.equalsIgnoreCase(sender)){
  114. for(int x=0; x <= message.length() - 1; x++){
  115. word += "_ ";
  116. }
  117. word.trim();
  118. wordIsCreated = true;
  119. if(!wordIsChosen){
  120. wordCreation.run();
  121. }
  122. }
  123. }
  124. }
  125.  
  126. public void startHangman(String sender){
  127. hangman = true;
  128. this.sender = sender;
  129. sendMessage(channel, "@" + sender + " " + "Whisper me the word you would like to use. For spaces, use _");
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement