Anope IRC Services  Version 1.8
bs_fantasy_kick.c
Go to the documentation of this file.
1 /* BotServ core fantasy functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_fantasy(int argc, char **argv);
18 
25 int AnopeInit(int argc, char **argv)
26 {
27  EvtHook *hook;
28 
29  moduleAddAuthor("Anope");
31  (VERSION_STRING);
33 
35  moduleAddEventHook(hook);
36 
37  return MOD_CONT;
38 }
39 
43 void AnopeFini(void)
44 {
45 
46 }
47 
54 static int do_fantasy(int argc, char **argv)
55 {
56  User *u, *u2;
57  ChannelInfo *ci;
58  char *target = NULL;
59  char *reason = NULL;
60 
61  if (argc < 3)
62  return MOD_CONT;
63 
64  if ((stricmp(argv[0], "kick") == 0) || (stricmp(argv[0], "k") == 0)) {
65  u = finduser(argv[1]);
66  ci = cs_findchan(argv[2]);
67  if (!u || !ci)
68  return MOD_CONT;
69 
70  if (argc >= 4) {
71  target = myStrGetToken(argv[3], ' ', 0);
72  reason = myStrGetTokenRemainder(argv[3], ' ', 1);
73  }
74  if (!target && check_access(u, ci, CA_KICKME)) {
75  bot_raw_kick(u, ci, u->nick, "Requested");
76  } else if (target && check_access(u, ci, CA_KICK)) {
77  if (!stricmp(target, ci->bi->nick))
78  bot_raw_kick(u, ci, u->nick, "Oops!");
79  else {
80  u2 = finduser(target);
81  if (u2 && ci->c && is_on_chan(ci->c, u2)) {
82  if (!reason && !is_protected(u2))
83  bot_raw_kick(u, ci, target, "Requested");
84  else if (!is_protected(u2))
85  bot_raw_kick(u, ci, target, reason);
86  }
87  }
88  }
89  }
90 
91  if (target)
92  free(target);
93  if (reason)
94  free(reason);
95 
96  return MOD_CONT;
97 }
#define CA_KICKME
Definition: services.h:778
char nick[NICKMAX]
Definition: services.h:875
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
E int is_on_chan(Channel *c, User *u)
Definition: channels.c:517
E int is_protected(User *user)
Definition: users.c:924
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, char *reason)
Definition: botserv.c:1001
MDE void moduleSetType(MODType type)
Definition: modules.c:818
#define CA_KICK
Definition: services.h:779
int AnopeInit(int argc, char **argv)
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
struct channel_ * c
Definition: services.h:692
MDE EvtHook * createEventHook(char *name, int(*func)(int argc, char **argv))
Definition: events.c:305
void AnopeFini(void)
#define MOD_CONT
Definition: modules.h:54
#define EVENT_BOT_FANTASY
Definition: events.h:24
Definition: modules.h:99
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
BotInfo * bi
Definition: services.h:699
static int do_fantasy(int argc, char **argv)
MDE int moduleAddEventHook(EvtHook *evh)
Definition: events.c:528