Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vivabenfica4ps3.gmail;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.Collection;
- import java.util.Map;
- import java.util.Scanner;
- import org.ho.yaml.Yaml;
- import org.jibble.pircbot.*;
- public class ToddBot extends PircBot
- {
- private String channel = "#anotherfail";
- private boolean hangman = false;
- private String hangmanword = "";
- private String word = "";
- private String sender;
- private boolean wordIsCreated = false;
- private boolean wordIsChosen = false;
- StringBuilder wordSolve;
- Thread wordCreation = new Thread(){
- @Override
- public void run() {
- if(wordIsCreated = true){
- System.out.println("The word is: " + word);
- wordSolve = new StringBuilder(word);
- sendMessage(channel, "[HANGMAN] The word is " + wordSolve);
- wordIsChosen = true;
- }
- else{
- sendMessage(channel, "No word has been selected. Game Cancelled");
- }
- }
- };;
- public ToddBot(String username) {
- this.setName(username);
- }
- public void test(){
- System.out.println("This Worked!");
- }
- @Override
- public void onMessage(String channel, String sender, String login, String hostname, String message) {
- String responce;
- boolean commandIsSaid = true;
- switch(message){
- 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";
- break;
- case "!commands": responce = "Current Commands: !info, !donate, !hangman, !rules, !commands";
- break;
- case "!donate": responce = "If you are feeling generous today and would like to send me a donation click on the Donate Icon below!";
- break;
- case "!hangman": responce = "has started a hangman game! Guess letters to enter or the whole word!"; if(!hangman && !wordIsCreated && !wordIsChosen)startHangman(sender);
- break;
- 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!";
- break;
- default: responce = ""; commandIsSaid = false;
- break;
- }
- if(commandIsSaid){
- if(message.equals("!hangman") && hangman && wordIsCreated && wordIsChosen){
- sendMessage(channel, "@" + sender + " There is currently a hangman in progress.");
- }
- else{
- sendMessage(channel, "@" + sender + " " + responce);
- }
- }
- if(hangman == true){
- if(hangmanword.contains(message.toUpperCase()) && message.length() == 1){
- for(int x = 0; x <= (hangmanword.length()-1); x++){
- if(hangmanword.substring(x, x+1).equals(message.toUpperCase())){
- wordSolve.setCharAt(x * 2, message.toUpperCase().charAt(0));
- }
- }
- if(wordSolve.toString().trim().equals(hangmanword.replace("", " ").trim())){
- sendMessage(channel, sender + " has guessed the final letter, the word is " + hangmanword + " Congratulations @" + sender); hangman = false; word = ""; wordIsCreated = false; wordIsChosen = false;
- }
- 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;}
- else sendMessage(channel, "@" + sender + " has guessed a letter, word is now: " + wordSolve);
- }
- }
- }
- public void parseYaml(){
- final String fileName = "C:/Users/Samuel/Desktop/Commands.yml";
- Yaml yaml = new Yaml();
- try {
- InputStream ios = new FileInputStream(new File(fileName));
- // Parse the YAML file and return the output as a series of Maps and Lists
- Map<String,Object> command = (Map<String,Object>)yaml.load(ios);
- Collection<Object> responce = command.values();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onUnknown(String line){
- if(line.contains(":" + sender + "!" + sender + "@" + sender + ".tmi.twitch.tv WHISPER toddbutler :")){
- String message = line.substring(line.lastIndexOf(" :") + 2);
- hangmanword = message.toUpperCase();
- System.out.println(message);
- if(hangman == true && this.sender.equalsIgnoreCase(sender)){
- for(int x=0; x <= message.length() - 1; x++){
- word += "_ ";
- }
- word.trim();
- wordIsCreated = true;
- if(!wordIsChosen){
- wordCreation.run();
- }
- }
- }
- }
- public void startHangman(String sender){
- hangman = true;
- this.sender = sender;
- sendMessage(channel, "@" + sender + " " + "Whisper me the word you would like to use. For spaces, use _");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement