Omnimaga
General Discussion => Technology and Development => Web Programming and Design => Topic started by: Spyro543 on July 19, 2011, 08:40:42 am
-
I'm needing some help with PircBot (documentation (http://www.jibble.org/javadocs/pircbot/index.html)). 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:
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.");
}
}
}
}
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:
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.
-
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.
-
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.
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.
-
Thats because you're trying to declare a method within a method, because your method before it was never closed.
-
I'll see what I can do.
-
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.
-
Now I've added some more things for the bot to do, and fixed the braces, and look at this:
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:
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.");
}
}
}
-
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:
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.
-
That code throws four errors:
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$
-
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.
-
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:
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.");
}
}
}
}
}
-
I want to enter another if (message.equalsIgnoreCase( outside of the checks for what user sent the message. Where can I put this?
-
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?
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.
-
Ew, chained if statements. Case checking is better. ;). And in many cases, faster.
-
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.
-
In this case it would be great. You could just evaluate what sender.equalsIgnoreCase() returns once and have a case switch for different strings.
-
I'm actually using Pybotlib now. Much easier.