It is currently Sun Dec 22, 2024 2:19 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post Post subject: Magic 8 Ball for Interactus
 
Offline
Unstoppable
Unstoppable
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership

Joined: Sun Nov 15, 2009 8:40 pm
Posts: 1038
Karma: 10
Right, got bored and did this, then got more bored so I started logging stuff, then got even more bored and commented on it all.

Code:
    public void save_strings(String text)
    {
      try
      {
        BufferedWriter out = new BufferedWriter(new FileWriter("magic ball.txt", true)); // setup file and append set to true
        text.replaceAll("!magicball", "");    // Remove the '!magicball' from the string
        out.write(text + "\n");   // write the string to the file, followed by a new line
        out.close();              // close the file
      } catch (IOException e) {}
    }

    /**
     * function to return a string to answer a question?
     */
    public String magic_reply()
    {
     String[] reply = { // There are 17
         "As I see it, yes",
         "It is certain",
         "It is decidedly so",
         "Most likely",
         "Outlook good",
         "Signs point to yes",
         "Without a doubt",
         "Yes",
         "Yes - Definatly",
         "You may rely on it",
         "Better not tell you now",
         "Concentrate and ask again",
         "Don't count on it",
         "My reply is no",
         "My sources say no",
         "The outlook is not so good",
         "It is very doubtful"};
     String text = "The answer to your question: ";

     Random generator = new Random(); // Make an object-Random number
     int r = generator.nextInt(17);   // Set that object to be between 0 and 16
     text += reply[r];                // Combine strings 'text' and the random string together
     return text;                     // Return the newly combined string
    }



    /**
     * Void function for handling a Channel message (handlesChanMessage() will
     * be called first to determine if takeChanMessage(channel, user, message)
     * should be called.)
     * @param channel Channel that the message came from.
     * @param user User that the message came from.
     * @param message The message sent by the user.
     */
    public void takeChanMessage(String channel, String user, String message)
    {
        boolean do_we_save_strings = true;
          if(message.startsWith ("!magicball"))
          {
              Interactus.sendMessage(channel, magic_reply());
              if (do_we_save_strings)     // If set to true, it will write down strings
                  save_strings(message);
          }
          // Interactus.sendMessage(channel, getConfig("text1"));
    }



@Si - Couldn't be bothered to figure out git :)

_________________
Skillers wrote:
Oh gawd no! Not the crazy frog! Arghhhhhh! $&^%&*^%*&#$^ %$(%^((% %$(O*%(#*%^ %)*#$&%)*@#% %_(#&%*%) frog


Mon Jul 26, 2010 1:39 am 
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Karma functions powered by Karma MOD © 2007, 2009 m157y