bs_act.c

Go to the documentation of this file.
00001 /* BotServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  *
00012  */
00013 /*************************************************************************/
00014 
00015 #include "module.h"
00016 
00017 static int do_act(User * u);
00018 static void myBotServHelp(User * u);
00019 
00026 int AnopeInit(int argc, char **argv)
00027 {
00028     Command *c;
00029 
00030     moduleAddAuthor("Anope");
00031     moduleAddVersion(VERSION_STRING);
00032     moduleSetType(CORE);
00033     c = createCommand("ACT", do_act, NULL, BOT_HELP_ACT, -1, -1, -1, -1);
00034     moduleAddCommand(BOTSERV, c, MOD_UNIQUE);
00035 
00036     moduleSetBotHelp(myBotServHelp);
00037 
00038     return MOD_CONT;
00039 }
00040 
00044 void AnopeFini(void)
00045 {
00046 
00047 }
00048 
00053 static void myBotServHelp(User * u)
00054 {
00055     notice_lang(s_BotServ, u, BOT_HELP_CMD_ACT);
00056 }
00057 
00063 static int do_act(User * u)
00064 {
00065     ChannelInfo *ci;
00066 
00067     char *chan = strtok(NULL, " ");
00068     char *text = strtok(NULL, "");
00069 
00070     if (!chan || !text)
00071         syntax_error(s_BotServ, u, "ACT", BOT_ACT_SYNTAX);
00072     else if (!(ci = cs_findchan(chan)))
00073         notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan);
00074     else if (ci->flags & CI_VERBOTEN)
00075         notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan);
00076     else if (!check_access(u, ci, CA_SAY))
00077         notice_lang(s_BotServ, u, ACCESS_DENIED);
00078     else if (!ci->bi)
00079         notice_help(s_BotServ, u, BOT_NOT_ASSIGNED);
00080     else if (!ci->c || ci->c->usercount < BSMinUsers)
00081         notice_lang(s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name);
00082     else {
00083         strnrepl(text, BUFSIZE, "\001", "");
00084         anope_cmd_action(ci->bi->nick, ci->name, "%s", text);
00085         ci->bi->lastmsg = time(NULL);
00086         if (LogBot && LogChannel && logchan && !debug && findchan(LogChannel))
00087             anope_cmd_privmsg(ci->bi->nick, LogChannel, "ACT %s %s %s",
00088                               u->nick, ci->name, text);
00089     }
00090     return MOD_CONT;
00091 }