1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Merge pull request #1525 from ailin-nemui/bans

fix /ban command
This commit is contained in:
ailin-nemui 2024-04-12 21:18:39 +00:00 committed by GitHub
commit 5c15937554
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 39 deletions

View File

@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
#define IRSSI_ABI_VERSION 53
#define IRSSI_ABI_VERSION 54
#define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697

View File

@ -35,6 +35,7 @@
#include <irssi/src/fe-common/core/printtext.h>
#include <irssi/src/fe-common/core/fe-channels.h>
#include <irssi/src/fe-common/irc/fe-irc-server.h>
#include <irssi/src/fe-common/irc/fe-irc-channels.h>
static void print_event_received(IRC_SERVER_REC *server, const char *data,
const char *nick, int target_param);
@ -138,38 +139,6 @@ static void event_end_of_who(IRC_SERVER_REC *server, const char *data)
g_free(params);
}
/* Get time elapsed since an event */
static char *time_ago(time_t seconds)
{
static char ret[128];
long unsigned years, weeks, days, hours, minutes;
seconds = time(NULL) - seconds;
years = seconds / (86400 * 365);
seconds %= (86400 * 365);
weeks = seconds / 604800;
days = (seconds / 86400) % 7;
hours = (seconds / 3600) % 24;
minutes = (seconds / 60) % 60;
seconds %= 60;
if (years)
snprintf(ret, sizeof(ret), "%luy %luw %lud", years, weeks, days);
else if (weeks)
snprintf(ret, sizeof(ret), "%luw %lud %luh", weeks, days, hours);
else if (days)
snprintf(ret, sizeof(ret), "%lud %luh %lum", days, hours, minutes);
else if (hours)
snprintf(ret, sizeof(ret), "%luh %lum", hours, minutes);
else if (minutes)
snprintf(ret, sizeof(ret), "%lum %lus", minutes, (long unsigned) seconds);
else
snprintf(ret, sizeof(ret), "%lus", (long unsigned) seconds);
return ret;
}
static void event_ban_list(IRC_SERVER_REC *server, const char *data)
{
IRC_CHANNEL_REC *chanrec;

View File

@ -73,6 +73,38 @@ const char *fe_channel_skip_prefix(IRC_SERVER_REC *server, const char *target)
return target;
}
/* Get time elapsed since an event */
char *time_ago(time_t seconds)
{
static char ret[128];
long unsigned years, weeks, days, hours, minutes;
seconds = time(NULL) - seconds;
years = seconds / (86400 * 365);
seconds %= (86400 * 365);
weeks = seconds / 604800;
days = (seconds / 86400) % 7;
hours = (seconds / 3600) % 24;
minutes = (seconds / 60) % 60;
seconds %= 60;
if (years)
snprintf(ret, sizeof(ret), "%luy %luw %lud", years, weeks, days);
else if (weeks)
snprintf(ret, sizeof(ret), "%luw %lud %luh", weeks, days, hours);
else if (days)
snprintf(ret, sizeof(ret), "%lud %luh %lum", days, hours, minutes);
else if (hours)
snprintf(ret, sizeof(ret), "%luh %lum", hours, minutes);
else if (minutes)
snprintf(ret, sizeof(ret), "%lum %lus", minutes, (long unsigned) seconds);
else
snprintf(ret, sizeof(ret), "%lus", (long unsigned) seconds);
return ret;
}
static void sig_channel_rejoin(SERVER_REC *server, REJOIN_REC *rec)
{
g_return_if_fail(rec != NULL);

View File

@ -3,6 +3,7 @@
int fe_channel_is_opchannel(IRC_SERVER_REC *server, const char *target);
const char *fe_channel_skip_prefix(IRC_SERVER_REC *server, const char *target);
char *time_ago(time_t seconds);
void fe_irc_channels_init(void);
void fe_irc_channels_deinit(void);

View File

@ -39,6 +39,7 @@
#include <irssi/src/fe-common/core/window-items.h>
#include <irssi/src/fe-common/core/printtext.h>
#include <irssi/src/fe-common/core/keyboard.h>
#include <irssi/src/fe-common/irc/fe-irc-channels.h>
/* SYNTAX: ME <message> */
static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
@ -224,15 +225,16 @@ static void bans_show_channel(IRC_CHANNEL_REC *channel, IRC_SERVER_REC *server)
/* show bans.. */
counter = 1;
for (tmp = channel->banlist; tmp != NULL; tmp = tmp->next) {
char *timestr, *ago;
BAN_REC *rec = tmp->data;
timestr = my_asctime(rec->time);
ago = time_ago(rec->time);
printformat(server, channel->visible_name, MSGLEVEL_CRAP,
(rec->setby == NULL || *rec->setby == '\0') ?
IRCTXT_BANLIST : IRCTXT_BANLIST_LONG,
counter, channel->visible_name,
rec->ban, rec->setby,
(int) (time(NULL)-rec->time));
counter++;
(rec->setby == NULL || *rec->setby == '\0') ? IRCTXT_BANLIST :
IRCTXT_BANLIST_LONG,
counter, channel->visible_name, rec->ban, rec->setby, ago, timestr);
counter++;
}
}