-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmins.java
More file actions
119 lines (106 loc) · 2.75 KB
/
Admins.java
File metadata and controls
119 lines (106 loc) · 2.75 KB
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
import java.io.*;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Scanner;
public class Admins implements Module{
private File file;
private HashSet<String> admins;
private String command = "admin";
private Message m;
private boolean admin;
public Admins(){
try {
this.file = new File(this.getClass().getResource("admins").toURI());
}
catch (URISyntaxException e) {}
admins = new HashSet<String>();
Scanner scan;
try {
scan = new Scanner(file);
while(scan.hasNext()){
admins.add(scan.nextLine());
}
}
catch (FileNotFoundException e) {
}
}
public void write(){
try {
PrintWriter writer = new PrintWriter(file);
for(String s : admins){
writer.println(s);
}
writer.close();
}
catch (IOException e) {}
}
public boolean has(String username){
return admins.contains(username);
}
public void add(String username){
admins.add(username);
}
public String getCommand() {
return command;
}
@Override
public String[] outputs() {
if(m.isBotCommand()){
if(m.getBotCommand().equals(command)){
String target = "PRIVMSG " + m.getParam();
if(!m.getParam().startsWith("#")) target = "NOTICE " + m.getSender();
boolean selfdelete = false;
String todo = "";
if(!admin){
todo = "privilege";
}
else if(!m.hasBotParams()){}
else if(m.getBotParams().get(0).equals("add")){
todo = "added";
for(int i = 1; i < m.getBotParams().size(); i++){
admins.add(m.getBotParams().get(i));
}
}
else if(m.getBotParams().get(0).equals("del")){
todo = "deleted";
for(int i = 1; i < m.getBotParams().size(); i++){
if(m.getBotParams().get(i).equals(m.getSender())){
selfdelete = true;
if(m.getBotParams().size() == 1){
todo = "selfdelete";
}
}
else admins.remove(m.getBotParams().get(i));
}
}
if(todo.equals("")){
String[] toreturn = new String[1];
toreturn[0] = target + " :Parameter not recognized. Usage: .add <parameter> <admins> Parameters are add, del ";
return toreturn;
}
else if(todo.equals("privilege")){
String[] toreturn = new String[1];
toreturn[0] = target + " :" + m.getSender() + ": You are not admin, please check your privilege";
return toreturn;
}
else{
String[] toreturn;
if(selfdelete){
toreturn = new String[2];
toreturn[1] = target + " :You cannot delete yourself from the admins list";
}
else toreturn = new String[1];
toreturn[0] = target + " :The specified admins have been " + todo;
write();
return toreturn;
}
}
}
return null;
}
@Override
public void parse(Message message, boolean isadmin) {
m = message;
admin = isadmin;
}
}