Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 06:51:57 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: PircBot 1.5.0 help needed with opping a user -  (Read 908 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« on: 19 July, 2011, 14:40:42 »
0

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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.");
}
}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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.

* BryceBotMain.java (0.28 KB - downloaded 20 times.)
* BryceBot.java (1.35 KB - downloaded 27 times.)
Logged

Ashbad
Guest
« Reply #1 on: 19 July, 2011, 15:12:47 »
0

It seems as though you didn't close most of your methods with a curly brace Wink 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: 19 July, 2011, 15:13:48 by Ashbad » Logged
Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« Reply #2 on: 19 July, 2011, 15:16:12 »
0

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.
Logged

Ashbad
Guest
« Reply #3 on: 19 July, 2011, 15:18:26 »
0

Thats because you're trying to declare a method within a method, because your method before it was never closed.
Logged
Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« Reply #4 on: 19 July, 2011, 15:19:37 »
0

I'll see what I can do.
Logged

Ashbad
Guest
« Reply #5 on: 19 July, 2011, 15:23:07 »
0


1
2
3
4
5
6
7
8
9
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: 19 July, 2011, 15:23:28 by Ashbad » Logged
Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« Reply #6 on: 19 July, 2011, 15:26:31 »
0

Now I've added some more things for the bot to do, and fixed the braces, and look at this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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.");
}
}
}
Logged

Ashbad
Guest
« Reply #7 on: 19 July, 2011, 16:53:23 »
0

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 Wink here is the code, fixed for these errors:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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.
Logged
Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« Reply #8 on: 19 July, 2011, 16:59:32 »
0

That code throws four errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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$
Logged

graphmastur
King Graphmastur
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 February, 2013, 08:34:45
Date Registered: 03 June, 2010, 21:15:55
Posts: 2262


Total Post Ratings: +60

View Profile
« Reply #9 on: 19 July, 2011, 17:16:22 »
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.
Logged

Ti-Programmer
LV3 Member (Next: 100)
***
Offline Offline

Last Login: 04 May, 2013, 01:59:47
Date Registered: 11 July, 2011, 08:14:15
Posts: 84


Total Post Ratings: +3

View Profile WWW
« Reply #10 on: 19 July, 2011, 19:14:30 »
0

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:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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: 19 July, 2011, 19:51:33 by Ti-Programmer » Logged

Spoiler for Sig:






Spyro543
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 02:36:26
Date Registered: 15 April, 2011, 01:42:09
Location: Ohio
Posts: 990


Topic starter
Total Post Ratings: +59

View Profile WWW
« Reply #11 on: 19 July, 2011, 19:57:51 »
0

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: 19 July, 2011, 19:59:32 by Spyro543 » Logged

graphmastur
King Graphmastur
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 February, 2013, 08:34:45
Date Registered: 03 June, 2010, 21:15:55
Posts: 2262


Total Post Ratings: +60

View Profile
« Reply #12 on: 19 July, 2011, 20:01:45 »
0

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

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. 
Logged

Ashbad
Guest
« Reply #13 on: 19 July, 2011, 20:24:58 »
0

Ew, chained if statements.  Case checking is better.  Wink.  And in many cases, faster.
Logged
graphmastur
King Graphmastur
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 February, 2013, 08:34:45
Date Registered: 03 June, 2010, 21:15:55
Posts: 2262


Total Post Ratings: +60

View Profile
« Reply #14 on: 19 July, 2011, 20:27:44 »
0

Ew, chained if statements.  Case checking is better.  Wink.  And in many cases, faster.
Not necessarily in this case, nor in all cases, is case checking better.
Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.381 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.