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
|
package f00f.net.irc.martyr.commands;
import f00f.net.irc.martyr.InCommand;
import f00f.net.irc.martyr.State;
import f00f.net.irc.martyr.clientstate.ClientState;
import f00f.net.irc.martyr.util.FullNick;
/**
* Defines the NOTICE command.
*/
public class NoticeCommand extends AbstractCommand
{
private FullNick from;
private String dest;
private String notice;
/** Factory */
public NoticeCommand()
{
from = null;
dest = null;
notice = null;
}
public NoticeCommand( String notice )
{
this.notice = notice;
}
public NoticeCommand( String dest, String notice )
{
this(null, dest, notice);
}
public NoticeCommand( FullNick dest, String notice )
{
this(dest.getNick(), notice);
}
public NoticeCommand( FullNick source, String dest, String notice ) {
this.from = source;
this.dest = dest;
this.notice = notice;
}
public State getState()
{
return State.UNKNOWN;
}
/**
* Parses a string and produces a formed command object, if it can.
* Should return null if it cannot form the command object.
*/
public InCommand parse( String prefix, String identifier, String params )
{
FullNick from;
if( prefix == null || prefix.trim().length() == 0 )
{
from = null;
}
else
{
from = new FullNick( prefix );
}
String dest = getParameter( params, 0 );
String msg = getParameter( params, 1 );
if( CtcpNotice.isCtcpString( msg ) )
{
return new CtcpNotice( from, dest, msg );
}
return new NoticeCommand( from, dest, msg );
}
/**
* Returns the string IRC uses to identify this command. Examples:
* NICK, PING, KILL, 332
*/
public String getIrcIdentifier()
{
return "NOTICE";
}
/**
* Renders the parameters of this command.
*/
public String renderParams()
{
if (dest != null) {
return dest + " :" + notice;
}
else {
return ":" + notice;
}
}
public FullNick getFrom()
{
return from;
}
public String getDest()
{
return dest;
}
public String getNotice()
{
return notice;
}
/**
* Returns true if the message is both private and for us.
*
* @param state Client state to compare with
* @return True or false if this is a private message to us
*/
public boolean isPrivateToUs( ClientState state )
{
return state.getNick().equals( dest );
}
}
|