summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/commands/TopicCommand.java
blob: 42e3d0421522e254315267dda6bce3111bb9fd00 (plain)
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
package f00f.net.irc.martyr.commands;

import java.util.Date;

import f00f.net.irc.martyr.CommandRegister;
import f00f.net.irc.martyr.InCommand;
import f00f.net.irc.martyr.clientstate.Channel;
import f00f.net.irc.martyr.clientstate.ClientState;

public class TopicCommand extends AbstractCommand
{
    //static Logger log = Logger.getLogger(TopicCommand.class);

    private String channel;
    private String topic;

    public static final String IDENTIFIER_PRIMARY = "TOPIC";
    public static final String IDENTIFIER_SECONDARY = "332";

    public TopicCommand()
    {
        this( null, null );
    }

    public TopicCommand( String channel, String topic )
    {
        this.channel = channel;
        this.topic = topic;
    }

    public String getIrcIdentifier()
    {
        //
        // This command uses "TOPIC" on outgoing, so that is why we use
        // "TOPIC" here instead of "332".
        //
        return IDENTIFIER_PRIMARY;
    }

    public void selfRegister( CommandRegister commandRegister )
    {
        commandRegister.addCommand( IDENTIFIER_PRIMARY, this );
        commandRegister.addCommand( IDENTIFIER_SECONDARY, this );
    }

    public InCommand parse( String prefix, String identifier, String params )
    {
        // when the command is used as a reply, the nick is parameter 0.
        if( identifier.equals( IDENTIFIER_SECONDARY ) )
            return new TopicCommand( getParameter(params, 1), getParameter(params, 2) );
        else
            return new TopicCommand( getParameter(params, 0), getParameter(params, 1) );
    }

    public String renderParams()
    {
        return getChannel() + " :" + getTopic();
    }

    public String getTopic()
    {
        return topic;
    }

    public String getChannel()
    {
        return channel;
    }

    public boolean updateClientState( ClientState state )
    {
        //log.debug("Topic: Channel: " + channel);
        Channel chan = state.getChannel( channel );
        chan.setTopic( topic );
        chan.setTopicDate( new Date() );
        return true;
    }

}