Remember channel's topic and print on /topic

This commit is contained in:
Sebastian Kaspari 2010-03-09 23:35:40 +01:00
parent c5dc8115d2
commit 3b8f6ee494
3 changed files with 27 additions and 3 deletions

View File

@ -41,7 +41,7 @@ public class TopicCommand extends BaseCommand
{
if (params.length == 1) {
// Show topic
// XXX: PircBot doesn't save the channel's topic - we have to keep track of the topic in the channel class
service.getConnection(server.getId()).onTopic(channel.getName(), channel.getTopic(), "", 0, false);
} else if (params.length > 1) {
// Change topic
service.getConnection(server.getId()).setTopic(channel.getName(), BaseCommand.mergeParams(params));

View File

@ -384,7 +384,7 @@ public class IRCConnection extends PircBot
* On Topic
*/
@Override
protected void onTopic(String target, String topic, String setBy, long date, boolean changed)
public void onTopic(String target, String topic, String setBy, long date, boolean changed)
{
debug("Topic", target + " " + setBy + " " + topic);
@ -398,8 +398,10 @@ public class IRCConnection extends PircBot
server.getChannel(target).addMessage(message);
}
// remember channel's topic
server.getChannel(target).setTopic(topic);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);

View File

@ -32,6 +32,7 @@ public class Channel
private static final int BUFFER_SIZE = 30;
private String name;
private String topic;
private LinkedList<Message> buffer = new LinkedList<Message>();
private LinkedList<Message> history = new LinkedList<Message>();
@ -43,6 +44,7 @@ public class Channel
public Channel(String name)
{
this.name = name;
this.topic = "";
}
/**
@ -103,4 +105,24 @@ public class Channel
{
buffer.clear();
}
/**
* Set the channel's topic
*
* @param topic The topic of the channel
*/
public void setTopic(String topic)
{
this.topic = topic;
}
/**
* Get the topic of the channel
*
* @return The channel's topic
*/
public String getTopic()
{
return topic;
}
}