Anope IRC Services  Version 1.8
bs_say.c
Go to the documentation of this file.
1 /* BotServ core 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_say(User * u);
18 static void myBotServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33  c = createCommand("SAY", do_say, NULL, BOT_HELP_SAY, -1, -1, -1, -1);
35 
37 
38  return MOD_CONT;
39 }
40 
44 void AnopeFini(void)
45 {
46 
47 }
48 
49 
50 
55 static void myBotServHelp(User * u)
56 {
57  notice_lang(s_BotServ, u, BOT_HELP_CMD_SAY);
58 }
59 
65 static int do_say(User * u)
66 {
67  ChannelInfo *ci;
68 
69  char *chan = strtok(NULL, " ");
70  char *text = strtok(NULL, "");
71 
72  if (!chan || !text)
73  syntax_error(s_BotServ, u, "SAY", BOT_SAY_SYNTAX);
74  else if (!(ci = cs_findchan(chan)))
75  notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan);
76  else if (ci->flags & CI_VERBOTEN)
77  notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan);
78  else if (!check_access(u, ci, CA_SAY))
79  notice_lang(s_BotServ, u, ACCESS_DENIED);
80  else if (!ci->bi)
81  notice_help(s_BotServ, u, BOT_NOT_ASSIGNED);
82  else if (!ci->c || ci->c->usercount < BSMinUsers)
83  notice_lang(s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name);
84  else {
85  if (text[0] != '\001') {
86  anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", text);
87  ci->bi->lastmsg = time(NULL);
90  "SAY %s %s %s", u->nick, ci->name, text);
91  } else {
92  syntax_error(s_BotServ, u, "SAY", BOT_SAY_SYNTAX);
93  }
94  }
95  return MOD_CONT;
96 }
int16 usercount
Definition: services.h:1020
E int LogBot
Definition: extern.h:438
char nick[NICKMAX]
Definition: services.h:875
E char * s_BotServ
Definition: extern.h:287
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
#define CI_VERBOTEN
Definition: services.h:725
E int BSMinUsers
Definition: extern.h:422
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E Channel * findchan(const char *chan)
Definition: channels.c:394
void AnopeFini(void)
Definition: bs_say.c:44
uint32 flags
Definition: services.h:669
static int do_say(User *u)
Definition: bs_say.c:65
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
struct channel_ * c
Definition: services.h:692
Command * c
Definition: ns_recover.c:17
#define BOTSERV
Definition: modules.h:57
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
time_t lastmsg
Definition: services.h:581
#define MOD_CONT
Definition: modules.h:54
MDE void moduleSetBotHelp(void(*func)(User *u))
Definition: modules.c:2114
E int debug
Definition: extern.h:775
E int logchan
Definition: extern.h:777
int AnopeInit(int argc, char **argv)
Definition: bs_say.c:26
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E char * LogChannel
Definition: extern.h:280
E void anope_cmd_privmsg(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:296
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
#define CA_SAY
Definition: services.h:766
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
static void myBotServHelp(User *u)
Definition: bs_say.c:55
#define MOD_UNIQUE
Definition: module.h:11