-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.java
More file actions
116 lines (102 loc) · 2.64 KB
/
Message.java
File metadata and controls
116 lines (102 loc) · 2.64 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
import java.util.ArrayList;
public class Message {
private String commandChar = ".";
private String sender = "";
private String senderaddress = "";
private String user = "";
private String command = "";
public String param = "";
private String trailing = "";
private boolean isbotcommand = false;
private String botcommand = "";
private ArrayList<String> botparams = new ArrayList<String>();
public Message(String message){
String[] messageSplit = message.split("\\s+");
/**
System.out.println(messageSplit.length);
for(int i = 0; i < messageSplit.length; i++){
System.out.println(messageSplit[i]);
}
*/
if(messageSplit.length == 2){
sender = "";
command = messageSplit[0];
param = "";
trailing = messageSplit[1].substring(1);
for(int i = 2; i < messageSplit.length; i++){
trailing += " " + messageSplit[i];
}
}
else if(messageSplit.length == 3){
sender = messageSplit[0].substring(1);
command = messageSplit[1];
param = "";
trailing = messageSplit[2].substring(1);
for(int i = 3; i < messageSplit.length; i++){
trailing += " " + messageSplit[i];
}
}
else{
sender = messageSplit[0].substring(1);
command = messageSplit[1];
param = messageSplit[2];
trailing = messageSplit[3].substring(1);
for(int i = 4; i < messageSplit.length; i++){
trailing += " " + messageSplit[i];
}
if(trailing.startsWith(commandChar) && command.equals("PRIVMSG")){
isbotcommand = true;
String[] trailingSplit = trailing.split("\\s+");
botcommand = trailingSplit[0].substring(commandChar.length());
for(int i = 1; i < trailingSplit.length; i++){
botparams.add(trailingSplit[i]);
}
}
}
String[] sendersplit = sender.split("!");
if(sendersplit.length > 1){
sender = sendersplit[0];
senderaddress = sendersplit[1].split("@")[0].substring(1);
senderaddress = sendersplit[1].split("@")[1];
}
else{
senderaddress = sender;
}
}
public boolean hasBotParams(){
if(botparams.size() == 0) return false;
return true;
}
public String getSender(){
return sender;
}
public String getSenderAddress(){
return senderaddress;
}
public String getCommand(){
return command;
}
public String getParam(){
return param;
}
public String getTrailing(){
return trailing;
}
public boolean isBotCommand(){
return isbotcommand;
}
public String getBotCommand(){
return botcommand;
}
public ArrayList<String> getBotParams(){
return botparams;
}
public String getBotParamsString(){
String params = "";
for(int i = 0; i < botparams.size(); i++){
params += botparams.get(i) + " ";
}
params = params.trim();
return params;
}
}