]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/bantimer.c
Merge pull request #1 from meeb/meeb
[irc/quakenet/newserv.git] / chanserv / chancmds / bantimer.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: bantimer
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 2
7 * CMDDESC: Shows or changes the time after which bans are removed.
8 * CMDFUNC: csc_dobantimer
9 * CMDPROTO: int csc_dobantimer(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: BANTIMER <channel> [<duration>]
11 * CMDHELP: To help keep channels clear of the clutter of too many bans, Q can automatically
12 * CMDHELP: remove channel bans after a specified time. This command is used to alter that
13 * CMDHELP: time period, disable the feature, or show the current setting, where:
14 * CMDHELP: channel - the channel to use
15 * CMDHELP: duration - how long to remove channel bans after. If duration is 0 then channel
16 * CMDHELP: bans will not be automatically removed. If duration is not specified,
17 * CMDHELP: the current setting will be displayed. Suffixes can m (minutes),
18 * CMDHELP: h (hours), d (days), w (weeks), M (months) and y (years) can be used
19 * CMDHELP: to specify the duration, for example 3d, 1w, 1h30m.
20 * CMDHELP: Viewing the current setting requires operator (+o) access on the named channel.
21 * CMDHELP: Changing the setting requires master (+m) access on the named channel.
22 */
23
24 #include "../chanserv.h"
25 #include "../../nick/nick.h"
26 #include "../../lib/flags.h"
27 #include "../../lib/irc_string.h"
28 #include "../../channel/channel.h"
29 #include "../../parser/parser.h"
30 #include "../../irc/irc.h"
31 #include "../../localuser/localuserchannel.h"
32 #include <string.h>
33 #include <stdio.h>
34
35 int csc_dobantimer(void *source, int cargc, char **cargv) {
36 nick *sender=source;
37 chanindex *cip;
38 regchan *rcp;
39 int oldtimer;
40
41 if (cargc<1) {
42 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "bantimer");
43 return CMD_ERROR;
44 }
45
46 if (!(cip=cs_checkaccess(sender, cargv[0], CA_OPPRIV, NULL, "bantimer",
47 QPRIV_VIEWBANTIMER, 0)))
48 return CMD_ERROR;
49
50 rcp=cip->exts[chanservext];
51
52 if (cargc>1) {
53 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "bantimer",
54 QPRIV_CHANGEBANTIMER, 0))
55 return CMD_ERROR;
56
57 oldtimer=rcp->banduration;
58 rcp->banduration=durationtolong(cargv[1]);
59
60 if (rcp->banduration<=0) {
61 if(strcmp(cargv[1], "0")) {
62 rcp->banduration=oldtimer;
63 chanservstdmessage(sender, QM_INVALIDDURATION2, cargv[1]);
64 return CMD_ERROR;
65 }
66 rcp->banduration=0;
67 }
68
69 /* Arbitrary limit */
70 if (rcp->banduration > 31622400)
71 rcp->banduration = 31622400;
72
73 csdb_updatechannel(rcp);
74
75 cs_log(sender,"BANTIMER %s %s (%u -> %lu)",cip->name->content,cargv[1],oldtimer,rcp->banduration);
76 chanservstdmessage(sender, QM_DONE);
77 cs_timerfunc(cip);
78 }
79
80 if (rcp->banduration)
81 chanservstdmessage(sender, QM_CHANBANAUTOREMOVE, cargv[0], longtoduration(rcp->banduration, 1));
82 else
83 chanservstdmessage(sender, QM_NOCHANBANAUTOREMOVE, cargv[0]);
84
85 return CMD_OK;
86 }