Author Topic: PircBot 1.5.0 help needed with opping a user  (Read 4784 times)

0 Members and 1 Guest are viewing this topic.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
PircBot 1.5.0 help needed with opping a user
« on: July 19, 2011, 08:40:42 am »
I'm needing some help with PircBot (documentation). For some reason, when I add a second event to my bot code, javac completely fails to compile any of it. And I'm trying to op a user here, and it's not working out so well. Here are the two source code files:
Code: (BryceBot.java) [Select]
import org.jibble.pircbot.*;

public class BryceBot extends PircBot {
   
public BryceBot() {
this.setName("BryceBot");
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("KittyGirl")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("UbuntuGuy")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("Ti-PrgmR")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
}
Code: (BryceBotMain.java) [Select]
mport org.jibble.pircbot.*;

public class BryceBotMain {
   
public static void main(String[] args) throws Exception {
       
BryceBot bot = new BryceBot();

bot.setVerbose(true);
       
bot.connect("irc.SHOUTcast.net");

bot.joinChannel("#tiandubuntu");
       
}
   
}

When I try to compile the files above, I get this:
Code: (Terminal output) [Select]
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$ javac -classpath pircbot.jar:. *.java
BryceBot.java:16: illegal start of expression
public void onMessage(String channel, String sender,
^
BryceBot.java:16: illegal start of expression
public void onMessage(String channel, String sender,
       ^
BryceBot.java:16: ';' expected
public void onMessage(String channel, String sender,
                     ^
BryceBot.java:16: ';' expected
public void onMessage(String channel, String sender,
                                            ^
BryceBot.java:16: not a statement
public void onMessage(String channel, String sender,
                                             ^
BryceBot.java:16: ';' expected
public void onMessage(String channel, String sender,
                                                   ^
BryceBot.java:17: ';' expected
                       String login, String hostname, String message) {
                                           ^
BryceBot.java:17: not a statement
                       String login, String hostname, String message) {
                                            ^
BryceBot.java:17: ';' expected
                       String login, String hostname, String message) {
                                                    ^
BryceBot.java:17: ';' expected
                       String login, String hostname, String message) {
                                                                    ^
BryceBot.java:20: illegal start of expression
void op(channel, sender);
^
BryceBot.java:20: ';' expected
void op(channel, sender);
       ^
BryceBot.java:20: not a statement
void op(channel, sender);
        ^
BryceBot.java:20: ';' expected
void op(channel, sender);
               ^
BryceBot.java:20: not a statement
void op(channel, sender);
                 ^
BryceBot.java:20: ';' expected
void op(channel, sender);
                       ^
BryceBot.java:25: illegal start of expression
public void onMessage(String channel, String sender,
^
BryceBot.java:25: illegal start of expression
public void onMessage(String channel, String sender,
       ^
BryceBot.java:25: ';' expected
public void onMessage(String channel, String sender,
                     ^
BryceBot.java:25: ';' expected
public void onMessage(String channel, String sender,
                                            ^
BryceBot.java:25: not a statement
public void onMessage(String channel, String sender,
                                             ^
BryceBot.java:25: ';' expected
public void onMessage(String channel, String sender,
                                                   ^
BryceBot.java:26: ';' expected
                       String login, String hostname, String message) {
                                           ^
BryceBot.java:26: not a statement
                       String login, String hostname, String message) {
                                            ^
BryceBot.java:26: ';' expected
                       String login, String hostname, String message) {
                                                    ^
BryceBot.java:26: ';' expected
                       String login, String hostname, String message) {
                                                                    ^
BryceBot.java:29: illegal start of expression
void op(channel, sender);
^
BryceBot.java:29: ';' expected
void op(channel, sender);
       ^
BryceBot.java:29: not a statement
void op(channel, sender);
        ^
BryceBot.java:29: ';' expected
void op(channel, sender);
               ^
BryceBot.java:29: not a statement
void op(channel, sender);
                 ^
BryceBot.java:29: ';' expected
void op(channel, sender);
                       ^
BryceBot.java:34: illegal start of expression
public void onMessage(String channel, String sender,
^
BryceBot.java:34: illegal start of expression
public void onMessage(String channel, String sender,
       ^
BryceBot.java:34: ';' expected
public void onMessage(String channel, String sender,
                     ^
BryceBot.java:34: ';' expected
public void onMessage(String channel, String sender,
                                            ^
BryceBot.java:34: not a statement
public void onMessage(String channel, String sender,
                                             ^
BryceBot.java:34: ';' expected
public void onMessage(String channel, String sender,
                                                   ^
BryceBot.java:35: ';' expected
                       String login, String hostname, String message) {
                                           ^
BryceBot.java:35: not a statement
                       String login, String hostname, String message) {
                                            ^
BryceBot.java:35: ';' expected
                       String login, String hostname, String message) {
                                                    ^
BryceBot.java:35: ';' expected
                       String login, String hostname, String message) {
                                                                    ^
BryceBot.java:38: illegal start of expression
void op(channel, sender);
^
BryceBot.java:38: ';' expected
void op(channel, sender);
       ^
BryceBot.java:38: not a statement
void op(channel, sender);
        ^
BryceBot.java:38: ';' expected
void op(channel, sender);
               ^
BryceBot.java:38: not a statement
void op(channel, sender);
                 ^
BryceBot.java:38: ';' expected
void op(channel, sender);
                       ^
BryceBot.java:43: reached end of file while parsing
}
 ^
BryceBot.java:44: reached end of file while parsing

^
50 errors
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$

If I compile and run the bot with just the first event (the one that shows the time), it works fine, but if I even copy and paste that event and use that code to make a slightly different code block with it, it fails.
If anyone here knows how to use PircBot, I would greatly appreciate help. Thanks.

Ashbad

  • Guest
Re: PircBot 1.5.0 help needed with opping a user
« Reply #1 on: July 19, 2011, 09:12:47 am »
It seems as though you didn't close most of your methods with a curly brace ;) you closed all internal if statements inside, but not the actual methods.  Your errors are purely syntax errors from what I can tell.  Try adding curly braces.  Edit: I'm looking at BryceBot.java, BryceBotMain.java seems fine.
« Last Edit: July 19, 2011, 09:13:48 am by Ashbad »

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #2 on: July 19, 2011, 09:16:12 am »
All of the "errors" pointed out in the Terminal output aren't errors, but part of PircBot coding <_<. For example:
BryceBot.java:16: illegal start of expression
   public void onMessage(String channel, String sender,
   ^

There's no error there. That's perfectly fine code.

Quote from: Ashbad
It seems as though you didn't close most of your methods with a curly brace  you closed all internal if statements inside, but not the actual methods.  Your errors are purely syntax errors from what I can tell.  Try adding curly braces.
I double checked my curly braces, and there doesn't seem to be and error in them.

Ashbad

  • Guest
Re: PircBot 1.5.0 help needed with opping a user
« Reply #3 on: July 19, 2011, 09:18:26 am »
Thats because you're trying to declare a method within a method, because your method before it was never closed.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #4 on: July 19, 2011, 09:19:37 am »
I'll see what I can do.

Ashbad

  • Guest
Re: PircBot 1.5.0 help needed with opping a user
« Reply #5 on: July 19, 2011, 09:23:07 am »
Code: [Select]
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
}
        }

public void onMessage(String channel, String sender,

This code should work and get rid of a few errors since I added the brace.  This needs to be done to a few methods, and then it should work.  I've worked with pircbot before, and the actual content of the code looks fine.
« Last Edit: July 19, 2011, 09:23:28 am by Ashbad »

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #6 on: July 19, 2011, 09:26:31 am »
Now I've added some more things for the bot to do, and fixed the braces, and look at this:
Code: (Terminal output when compile command was sent) [Select]
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$ javac -classpath pircbot.jar:. *.java
BryceBot.java:13: illegal start of expression
public final void setTopic(channel,
^
BryceBot.java:13: illegal start of type
public final void setTopic(channel,
             ^
BryceBot.java:13: ';' expected
public final void setTopic(channel,
                 ^
BryceBot.java:13: ')' expected
public final void setTopic(channel,
                                  ^
BryceBot.java:13: not a statement
public final void setTopic(channel,
                          ^
BryceBot.java:14: not a statement
                           "Ti-PrgmR, KittyGirl, and UbuntuGuy's Channel. Type $rules for channel rules.");
                           ^
BryceBot.java:14: ';' expected
                           "Ti-PrgmR, KittyGirl, and UbuntuGuy's Channel. Type $rules for channel rules.");
                                                                                                         ^
BryceBot.java:28: illegal start of expression
void op(channel, sender);
^
BryceBot.java:28: ';' expected
void op(channel, sender);
       ^
BryceBot.java:28: not a statement
void op(channel, sender);
        ^
BryceBot.java:28: ';' expected
void op(channel, sender);
               ^
BryceBot.java:28: not a statement
void op(channel, sender);
                 ^
BryceBot.java:28: ';' expected
void op(channel, sender);
                       ^
BryceBot.java:37: illegal start of expression
void op(channel, sender);
^
BryceBot.java:37: ';' expected
void op(channel, sender);
       ^
BryceBot.java:37: not a statement
void op(channel, sender);
        ^
BryceBot.java:37: ';' expected
void op(channel, sender);
               ^
BryceBot.java:37: not a statement
void op(channel, sender);
                 ^
BryceBot.java:37: ';' expected
void op(channel, sender);
                       ^
BryceBot.java:46: illegal start of expression
void op(channel, sender);
^
BryceBot.java:46: ';' expected
void op(channel, sender);
       ^
BryceBot.java:46: not a statement
void op(channel, sender);
        ^
BryceBot.java:46: ';' expected
void op(channel, sender);
               ^
BryceBot.java:46: not a statement
void op(channel, sender);
                 ^
BryceBot.java:46: ';' expected
void op(channel, sender);
                       ^
25 errors
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$

Here's the source code:
Code: (new source code) [Select]
import org.jibble.pircbot.*;

public class BryceBot extends PircBot {
   
public BryceBot() {
this.setName("BryceBot");
}
protected void onJoin(String channel,
                      String sender,
                      String login,
                      String hostname) {
if(sender.equalsIgnoreCase("BryceBot")) {
public final void setTopic(channel,
                           "Ti-PrgmR, KittyGirl, and UbuntuGuy's Channel. Type $rules for channel rules.");
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("KittyGirl")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("UbuntuGuy")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("Ti-PrgmR")) {
void op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$rules")) {
sendMessage(channel, "Rules for #tiandubuntu - 1. Please don't troll other users. (Trolling is just basically being mean.) 2. Please no flaming. (Flaming is targeting someone and trying to make them upset.) 3. No useless spam. (Spam is advertising, or useless flooding.) 4. No full swear words. (If you censor it, like f*** or something or do FUUUUUUUUU it's OK. Commands you can use: If you are an owner of this channel, type '$op' to get opped. Type $time for the current time. '$rules' shows the rules and commands available.");
}
}
}

Ashbad

  • Guest
Re: PircBot 1.5.0 help needed with opping a user
« Reply #7 on: July 19, 2011, 10:53:23 am »
For the errors on line 13, it's because it seems as if you're declaring a method of some sort within an if statement O.o I think you meant to rather call setTopic() instead of create it, and also don't declare methods final, make them static.

In fact, that's what all of your errors are coming from.  You're trying to call methods, but what you're really doing is defining them where they can't be defined.  Don't put things like "void" in front of a method call, a void means that you're declaring a new method that returns nothing ;) here is the code, fixed for these errors:

Code: (fixed source code) [Select]
import org.jibble.pircbot.*;

public class BryceBot extends PircBot {
    
public BryceBot() {
this.setName("BryceBot");
}
protected void onJoin(String channel,
                      String sender,
                      String login,
                      String hostname) {
if(sender.equalsIgnoreCase("BryceBot")) {
setTopic(channel,
                           "Ti-PrgmR, KittyGirl, and UbuntuGuy's Channel. Type $rules for channel rules.");
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("KittyGirl")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("UbuntuGuy")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("Ti-PrgmR")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$rules")) {
sendMessage(channel, "Rules for #tiandubuntu - 1. Please don't troll other users. (Trolling is just basically being mean.) 2. Please no flaming. (Flaming is targeting someone and trying to make them upset.) 3. No useless spam. (Spam is advertising, or useless flooding.) 4. No full swear words. (If you censor it, like f*** or something or do FUUUUUUUUU it's OK. Commands you can use: If you are an owner of this channel, type '$op' to get opped. Type $time for the current time. '$rules' shows the rules and commands available.");
}
}
}

See how that works.  I'm just assuming that op() and setTopic don't need a "this." in front of them.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #8 on: July 19, 2011, 10:59:32 am »
That code throws four errors:
Code: (terminal output) [Select]
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$ javac -classpath pircbot.jar:. *.java
BryceBot.java:25: onMessage(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String) is already defined in BryceBot
public void onMessage(String channel, String sender,
            ^
BryceBot.java:34: onMessage(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String) is already defined in BryceBot
public void onMessage(String channel, String sender,
            ^
BryceBot.java:43: onMessage(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String) is already defined in BryceBot
public void onMessage(String channel, String sender,
            ^
BryceBot.java:52: onMessage(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String) is already defined in BryceBot
public void onMessage(String channel, String sender,
            ^
4 errors
aaron@aaron-N150P-N210P-N220P:~/BryceBot/pircbot-1.5.0$

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #9 on: July 19, 2011, 11:16:22 am »
Alright, guys, I've used PircBot A LOT before. I've also used java without any PircBot.  You cannot declare multiple methods of the same name, and expect it to work.  There is only one onMessage to override.

So put all of your if statements inside that one onMessage method.  What I do, is I create another class called BotonMessage, and have a static method called onMessage.  I create one Bot class, in your case I'm assuming it's going to be called BryceBot, and I implement the onMessage method with a call to BotonMessage.onMessage(), but I use the same parameters.  This makes your code a lot easier to manage.

Offline Ti-Programmer

  • LV3 Member (Next: 100)
  • ***
  • Posts: 84
  • Rating: +3/-0
  • Whats this? so many features...
    • View Profile
    • Ti-Programmer's website
Re: PircBot 1.5.0 help needed with opping a user
« Reply #10 on: July 19, 2011, 01:14:30 pm »
Yea, just like graphmastur said.

Don't declare 5 different void onMessage()'s
put all the if() statements in one onMessage(). I'll edit my post and see if I can get the source working here.

Ti-PrgmR


EDIT:

Code: (BryceBot.java) [Select]
import org.jibble.pircbot.*;

public class BryceBot extends PircBot {
public BryceBot() {
this.setName("BryceBot");
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("KittyGirl")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
if (sender.equalsIgnoreCase("UbuntuGuy")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
if (sender.equalsIgnoreCase("Ti-PrgmR")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
}
}
« Last Edit: July 19, 2011, 01:51:33 pm by Ti-Programmer »
Spoiler For Sig:







Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #11 on: July 19, 2011, 01:57:51 pm »
I want to enter another if (message.equalsIgnoreCase( outside of the checks for what user sent the message. Where can I put this?
« Last Edit: July 19, 2011, 01:59:32 pm by Spyro543 »

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #12 on: July 19, 2011, 02:01:45 pm »
I want to enter another if (message.equalsIgnoreCase( outside of the checks for what user sent the message. Where can I put this?
Um... what?
Code: [Select]

import org.jibble.pircbot.*;

public class BryceBot extends PircBot {
public BryceBot() {
this.setName("BryceBot");
}
   
public void onMessage(String channel, String sender,
                       String login, String hostname, String message) {
if (message.equalsIgnoreCase("$time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ", The time is now " + time);
}
if (message.equalsIgnoreCase("$op")) {
if (sender.equalsIgnoreCase("KittyGirl")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
if (sender.equalsIgnoreCase("UbuntuGuy")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
if (sender.equalsIgnoreCase("Ti-PrgmR")) {
op(channel, sender);
sendMessage(channel, sender + ", you have been opped.");
}
}
}
}

Also, this bot isn't very secure, because I can simply log in as "KittyGirl", get Opped, and do a /nick to graphmastur.  But if you don't want to check the sender, then don't check the sender. 

Ashbad

  • Guest
Re: PircBot 1.5.0 help needed with opping a user
« Reply #13 on: July 19, 2011, 02:24:58 pm »
Ew, chained if statements.  Case checking is better.  ;).  And in many cases, faster.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: PircBot 1.5.0 help needed with opping a user
« Reply #14 on: July 19, 2011, 02:27:44 pm »
Ew, chained if statements.  Case checking is better.  ;).  And in many cases, faster.
Not necessarily in this case, nor in all cases, is case checking better.