quote-bot/event_channel.c

66 lines
1.7 KiB
C
Raw Permalink Normal View History

2021-03-08 23:16:14 -05:00
void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
if ( !origin || count != 2 )
return;
if ( strstr (params[1], "fuck") == 0 )
return;
char nickbuf[128], text[256];
irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
if ( ctx->insolents.find(nickbuf) == ctx->insolents.end() )
ctx->insolents[nickbuf] = 0;
ctx->insolents[nickbuf]++;
printf ("'%s' swears in the channel '%s' %d times\n",
nickbuf,
params[1],
ctx->insolents[nickbuf]);
switch (ctx->insolents[nickbuf])
{
case 1:
// Send a private message
sprintf (text, "%s, please do not swear in this channel.", nickbuf);
irc_cmd_msg (session, nickbuf, text);
break;
case 2:
// Send a channel message
sprintf (text, "%s, do not swear in this channel, or you'll leave it.", nickbuf);
irc_cmd_msg (session, params[0], text);
break;
default:
// Send a channel notice, and kick the insolent
sprintf (text, "kicked %s from %s for swearing.", nickbuf, params[0]);
irc_cmd_me (session, params[0], text);
irc_cmd_kick (session, nickbuf, params[0], "swearing");
break;
}
}
void event_nick (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
char nickbuf[128];
irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
if ( !origin || count != 1 )
return;
irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
if ( ctx->insolents.find(nickbuf) != ctx->insolents.end() )
{
printf ("%s has changed its nick to %s to prevent penalties - no way!\n",
nickbuf, params[0]);
ctx->insolents[params[0]] = ctx->insolents[nickbuf];
ctx->insolents.erase (nickbuf);
}
}