mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05:00
Remember who set the topic and when, display the info when using /TOPIC.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@845 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
090e88b34d
commit
2edcdd715f
@ -3,6 +3,8 @@
|
|||||||
#include "window-item-rec.h"
|
#include "window-item-rec.h"
|
||||||
|
|
||||||
char *topic;
|
char *topic;
|
||||||
|
char *topic_by;
|
||||||
|
time_t topic_time;
|
||||||
GHashTable *nicks; /* list of nicks */
|
GHashTable *nicks; /* list of nicks */
|
||||||
|
|
||||||
int no_modes:1; /* channel doesn't support modes */
|
int no_modes:1; /* channel doesn't support modes */
|
||||||
|
@ -78,6 +78,7 @@ void channel_destroy(CHANNEL_REC *channel)
|
|||||||
|
|
||||||
MODULE_DATA_DEINIT(channel);
|
MODULE_DATA_DEINIT(channel);
|
||||||
g_free_not_null(channel->topic);
|
g_free_not_null(channel->topic);
|
||||||
|
g_free_not_null(channel->topic_by);
|
||||||
g_free_not_null(channel->key);
|
g_free_not_null(channel->key);
|
||||||
g_free(channel->mode);
|
g_free(channel->mode);
|
||||||
g_free(channel->name);
|
g_free(channel->name);
|
||||||
|
@ -322,6 +322,34 @@ static void cmd_ver(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
|
|||||||
g_free(str);
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||||
|
{
|
||||||
|
CHANNEL_REC *channel;
|
||||||
|
char *timestr;
|
||||||
|
struct tm *tm;
|
||||||
|
|
||||||
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
|
channel = *data != '\0' ? channel_find(server, data) : CHANNEL(item);
|
||||||
|
if (channel == NULL) return;
|
||||||
|
|
||||||
|
printformat(server, channel->name, MSGLEVEL_CRAP,
|
||||||
|
channel->topic == NULL ? IRCTXT_NO_TOPIC : IRCTXT_TOPIC,
|
||||||
|
channel->name, channel->topic);
|
||||||
|
|
||||||
|
if (channel->topic_time > 0) {
|
||||||
|
tm = localtime(&channel->topic_time);
|
||||||
|
timestr = g_strdup(asctime(tm));
|
||||||
|
if (timestr[strlen(timestr)-1] == '\n')
|
||||||
|
timestr[strlen(timestr)-1] = '\0';
|
||||||
|
|
||||||
|
printformat(server, channel->name, MSGLEVEL_CRAP,
|
||||||
|
IRCTXT_TOPIC_INFO, channel->topic_by, timestr);
|
||||||
|
g_free(timestr);
|
||||||
|
}
|
||||||
|
signal_stop();
|
||||||
|
}
|
||||||
|
|
||||||
/* SYNTAX: TS */
|
/* SYNTAX: TS */
|
||||||
static void cmd_ts(const char *data)
|
static void cmd_ts(const char *data)
|
||||||
{
|
{
|
||||||
@ -350,6 +378,7 @@ void fe_irc_commands_init(void)
|
|||||||
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
|
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
|
||||||
command_bind("nick", NULL, (SIGNAL_FUNC) cmd_nick);
|
command_bind("nick", NULL, (SIGNAL_FUNC) cmd_nick);
|
||||||
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
|
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
|
||||||
|
command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
|
||||||
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
|
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,5 +395,6 @@ void fe_irc_commands_deinit(void)
|
|||||||
command_unbind("join", (SIGNAL_FUNC) cmd_join);
|
command_unbind("join", (SIGNAL_FUNC) cmd_join);
|
||||||
command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
|
command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
|
||||||
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
|
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
|
||||||
|
command_unbind("topic", (SIGNAL_FUNC) cmd_topic);
|
||||||
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);
|
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);
|
||||||
}
|
}
|
||||||
|
@ -93,18 +93,28 @@ static void event_target_unavailable(const char *data, IRC_SERVER_REC *server)
|
|||||||
g_free(params);
|
g_free(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void channel_change_topic(IRC_SERVER_REC *server, const char *channel, const char *topic)
|
static void channel_change_topic(IRC_SERVER_REC *server, const char *channel,
|
||||||
|
const char *topic, const char *setby,
|
||||||
|
time_t settime)
|
||||||
{
|
{
|
||||||
CHANNEL_REC *chanrec;
|
CHANNEL_REC *chanrec;
|
||||||
|
|
||||||
chanrec = channel_find(SERVER(server), channel);
|
chanrec = channel_find(SERVER(server), channel);
|
||||||
if (chanrec != NULL) {
|
if (chanrec == NULL) return;
|
||||||
|
|
||||||
|
if (topic != NULL) {
|
||||||
g_free_not_null(chanrec->topic);
|
g_free_not_null(chanrec->topic);
|
||||||
chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
|
chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
|
||||||
|
|
||||||
signal_emit("channel topic changed", 1, chanrec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free_not_null(chanrec->topic_by);
|
||||||
|
chanrec->topic_by = g_strdup(setby);
|
||||||
|
|
||||||
|
chanrec->topic_time = settime;
|
||||||
|
|
||||||
|
signal_emit("channel topic changed", 1, chanrec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_topic_get(const char *data, IRC_SERVER_REC *server)
|
static void event_topic_get(const char *data, IRC_SERVER_REC *server)
|
||||||
{
|
{
|
||||||
char *params, *channel, *topic;
|
char *params, *channel, *topic;
|
||||||
@ -112,18 +122,34 @@ static void event_topic_get(const char *data, IRC_SERVER_REC *server)
|
|||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
params = event_get_params(data, 3, NULL, &channel, &topic);
|
params = event_get_params(data, 3, NULL, &channel, &topic);
|
||||||
channel_change_topic(server, channel, topic);
|
channel_change_topic(server, channel, topic, NULL, 0);
|
||||||
g_free(params);
|
g_free(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_topic(const char *data, IRC_SERVER_REC *server)
|
static void event_topic(const char *data, IRC_SERVER_REC *server,
|
||||||
|
const char *nick)
|
||||||
{
|
{
|
||||||
char *params, *channel, *topic;
|
char *params, *channel, *topic;
|
||||||
|
|
||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
params = event_get_params(data, 2, &channel, &topic);
|
params = event_get_params(data, 2, &channel, &topic);
|
||||||
channel_change_topic(server, channel, topic);
|
channel_change_topic(server, channel, topic, nick, time(NULL));
|
||||||
|
g_free(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void event_topic_info(const char *data, IRC_SERVER_REC *server)
|
||||||
|
{
|
||||||
|
char *params, *channel, *topicby, *topictime;
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
|
params = event_get_params(data, 4, NULL, &channel,
|
||||||
|
&topicby, &topictime);
|
||||||
|
|
||||||
|
t = (time_t) atol(topictime);
|
||||||
|
channel_change_topic(server, channel, NULL, topicby, t);
|
||||||
g_free(params);
|
g_free(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,6 +309,7 @@ void channel_events_init(void)
|
|||||||
signal_add("event kick", (SIGNAL_FUNC) event_kick);
|
signal_add("event kick", (SIGNAL_FUNC) event_kick);
|
||||||
signal_add("event invite", (SIGNAL_FUNC) event_invite);
|
signal_add("event invite", (SIGNAL_FUNC) event_invite);
|
||||||
signal_add("event 332", (SIGNAL_FUNC) event_topic_get);
|
signal_add("event 332", (SIGNAL_FUNC) event_topic_get);
|
||||||
|
signal_add("event 333", (SIGNAL_FUNC) event_topic_info);
|
||||||
signal_add_first("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
|
signal_add_first("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,5 +330,6 @@ void channel_events_deinit(void)
|
|||||||
signal_remove("event kick", (SIGNAL_FUNC) event_kick);
|
signal_remove("event kick", (SIGNAL_FUNC) event_kick);
|
||||||
signal_remove("event invite", (SIGNAL_FUNC) event_invite);
|
signal_remove("event invite", (SIGNAL_FUNC) event_invite);
|
||||||
signal_remove("event 332", (SIGNAL_FUNC) event_topic_get);
|
signal_remove("event 332", (SIGNAL_FUNC) event_topic_get);
|
||||||
|
signal_remove("event 333", (SIGNAL_FUNC) event_topic_info);
|
||||||
signal_remove("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
|
signal_remove("event 437", (SIGNAL_FUNC) event_target_unavailable); /* channel/nick unavailable */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user