-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntros.java
More file actions
147 lines (134 loc) · 4.15 KB
/
Intros.java
File metadata and controls
147 lines (134 loc) · 4.15 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
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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Properties;
public class Intros implements Module {
private String command = "intro";
private Message m;
private boolean admin;
private Properties props;
public Intros(){
read();
}
@Override
public String[] outputs() {
String[] outputs = new String[1];
if(m.getCommand().equals("JOIN")){
if(props.getProperty(m.getSender()) != null && !props.getProperty(m.getSender()).equals("")){
String intro = props.getProperty(m.getSender());
outputs[0] = "PRIVMSG " + m.getTrailing() + " :" + intro ;
return outputs;
}
}
if(m.isBotCommand()){
if(m.getBotCommand().equals(command)){
String target = "PRIVMSG " + m.getParam();
if(!m.getParam().startsWith("#")) target = "NOTICE " + m.getSender();
String todo = "";
String intro = "";
if(!m.hasBotParams()){}
else if(m.getSender().equals("installgen2") || m.getSender().equals("installgen2phone")){
todo = "no";
}
else if(m.getBotParams().get(0).equals("set")){
if(m.getBotParams().size() > 1){
todo = "set";
for(int i = 1; i < m.getBotParams().size(); i++){
intro += m.getBotParams().get(i) + " ";
}
if(intro.equals("")){
todo = "";
}
props.setProperty(m.getSender(), intro);
}
}
else if(m.getBotParams().get(0).equals("del")){
todo = "deleted";
if(props.getProperty(m.getSender()) != null){
props.setProperty(m.getSender(), "");
}
else{
todo = "nointro";
}
}
else if(m.getBotParams().get(0).equals("view")){
if(m.getBotParams().size() > 2){
todo = "toomany";
}
else if(m.getBotParams().size() == 2){
if(props.getProperty(m.getBotParams().get(1)) != null && !props.getProperty(m.getBotParams().get(1)).equals("")) todo = "viewother " + m.getBotParams().get(1);
else todo = "nointroother";
}
else if(props.getProperty(m.getSender()) != null && !props.getProperty(m.getSender()).equals("")) todo = "view";
else todo = "nointro";
}
try {
FileOutputStream out = new FileOutputStream(new File(this.getClass().getResource("intros.properties").toURI()));
props.store(out, "Intros");
out.close();
}
catch (IOException | URISyntaxException e) {}
if(todo.equals("")){
String[] toreturn = new String[1];
toreturn[0] = target + " :Parameter not recognized. Usage: .intro <parameter> <intro> Parameters are set, del, view ";
return toreturn;
}
if(todo.equals("nointro")){
String[] toreturn = new String[1];
toreturn[0] = target + " :You do not have an intro set";
return toreturn;
}
if(todo.equals("nointroother")){
String[] toreturn = new String[1];
toreturn[0] = target + " :Intro not found";
return toreturn;
}
if(todo.equals("toomany")){
String[] toreturn = new String[1];
toreturn[0] = target + " :Too many arguments. Usage: .intro view <user> ";
return toreturn;
}
if(todo.equals("no")){
String[] toreturn = new String[1];
toreturn[0] = target + " :fk u";
return toreturn;
}
if(todo.equals("view")){
String[] toreturn = new String[1];
toreturn[0] = target + " :" + props.getProperty(m.getSender());
return toreturn;
}
if(todo.startsWith("viewother")){
String[] toreturn = new String[1];
toreturn[0] = target + " :" + props.getProperty(todo.split("\\s+")[1]);
return toreturn;
}
else{
String[] toreturn;
toreturn = new String[1];
toreturn[0] = target + " :Your intro has been " + todo;
return toreturn;
}
}
}
return null;
}
public void read(){
InputStream stream = getClass().getClassLoader().getResourceAsStream("intros.properties");
Properties newprops = new Properties();
try {
newprops.load(stream);
props = newprops;
}
catch (IOException e) {}
}
@Override
public void parse(Message message, boolean isadmin) {
this.m = message;
this.admin = isadmin;
}
}