added strToTime function and started writing cmd_trim
[NeonServV5.git] / cmd_neonserv_trim.c
1
2 /*
3 * argv[0]  target (format: minaccess-maxaccess/users/bans)
4 * argv[1]  duration
5 * argv[2]  (optional) "vacation"
6 */
7
8 static CMD_BIND(neonserv_cmd_trim) {
9     check_mysql();
10     if(!checkChannelAccess(user, chan, "channel_candel", 1, 0)) {
11         reply(getTextBot(), user, "NS_ACCESS_DENIED");
12         return;
13     }
14     int min_access, max_access;
15     if(!strcmp(argv[0], "users")) {
16         min_access = 1;
17         max_access = getChannelAccess(user, chan, 0) - 1;
18     } else if(!strcmp(argv[0], "bans")) {
19         //TODO: TRIM BANS
20         return;
21     } else {
22         char *seperator = strstr(argv[0], "-");
23         if(seperator) {
24             seperator = '\0';
25             seperator++;
26             min_access = atoi(argv[0]);
27             max_access = atoi(seperator);
28             if(max_access > min_access) {
29                 reply(getTextBot(), user, "NS_INVALID_ACCESS_RANGE", min_access, max_access);
30                 return;
31             }
32         } else {
33             min_access = atoi(argv[0]);
34             max_access = min_access;
35         }
36         if(max_access >= getChannelAccess(user, chan, 1)) {
37             reply(getTextBot(), user, "NS_NO_ACCESS");
38             return;
39         }
40     }
41     //parse duration...
42     int duration = strToTime(user, argv[1]);
43     char timeBuf[MAXLEN];
44     reply(getTextBot(), user, "yea; time: %d  (%s)", duration, timeToStr(user, duration, 3, timeBuf));
45 }
46