This repository has been archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSpeechHandler.java
97 lines (85 loc) · 2.94 KB
/
SpeechHandler.java
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
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.PrivateMessageEvent;
import org.pircbotx.User;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import java.util.Scanner;
import java.util.Collections;
import java.util.LinkedList;
public class SpeechHandler extends ListenerAdapter {
private Scanner scanner;
private PermissionsManager pm;
private PircBotX bot;
private String channel;
public SpeechHandler(PircBotX bot, String channel) {
super();
this.bot = bot;
this.channel = channel;
this.pm = PermissionsManager.getInstance();
System.out.println("PermissionsHandler initialized.");
}
public void onPrivateMessage(PrivateMessageEvent event) {
String rawcommand = event.getMessage();
String command = rawcommand.toLowerCase();
if (command.startsWith("!speak ")) {
User user = event.getUser();
Channel channelobject = bot.getChannel(channel);
//check permissions
if (!pm.isAllowed("!speak",event.getUser(),channelobject)) {
event.respond("Sorry, you are not authorized to run this command.");
return;
}
scanner = new Scanner(command);
String token = scanner.next();
if (scanner.hasNext()){
token = scanner.next();
String newmessage = rawcommand.substring(7);
bot.sendMessage(channel, newmessage);
}
}
if (command.startsWith("!kick ")) {
User user = event.getUser();
Channel channelobject = bot.getChannel(channel);
//check permissions
if (!pm.isAllowed("!kick",event.getUser(),channelobject)) {
event.respond("Sorry, you are not authorized to run this command.");
return;
}
scanner = new Scanner(command);
String token = scanner.next(); //token is "!kick"
if (scanner.hasNext()){
String targetnick = scanner.next(); //token should be target nick
int nicklength = targetnick.length();
if (scanner.hasNext()) {
// there was a reason tacked on, too
String reason = rawcommand.substring(7+nicklength);
bot.kick(bot.getChannel(channel),bot.getUser(targetnick),reason);
return;
} else {
bot.kick(bot.getChannel(channel),bot.getUser(targetnick));
return;
}
}
}
if (command.startsWith("!ban ")) {
User user = event.getUser();
Channel channelobject = bot.getChannel(channel);
//check permissions
if (!pm.isAllowed("!ban",event.getUser(),channelobject)) {
event.respond("Sorry, you are not authorized to run this command.");
return;
}
scanner = new Scanner(command);
String token = scanner.next(); //token is "!ban"
if (scanner.hasNext()){
String targetnick = scanner.next(); //token should be target nick
String hostmask = bot.getUser(targetnick).getHostmask();
String realname = bot.getUser(targetnick).getRealName();
String login = bot.getUser(targetnick).getLogin();
String banmask = "*!"+login+"@"+hostmask;
event.respond(targetnick + " " + login + " " + realname + " " + hostmask);
event.respond(banmask);
}
}
}
}