Anope IRC Services
Anope Development => Modules => Topic started by: lavinpj1 on April 25, 2006, 06:45:23 PM
-
I'm playing with getting botserv to send a notice when they say command is used. I have added all the correct parts etc. and it works ok using the following code as the function...
int bs_sayalert(User *u)
{
notice(s_BotServ, u->nick, "You have used the Say command!");
return MOD_STOP;
}
Yet, if I then want to return the inputted params in the notice, using the following code...
int bs_sayalert(User *u)
{
char *curmodchan = strtok(NULL, " ");
char *saidtext = strtok(NULL, " ");
notice(s_BotServ, u->nick, "You have used the Say command in %s saying %s!", curmodchan, saidtext);
return MOD_CONT;
}
It sends the notice fine, yet it seems to strip those 2 params out of the command as it relays to botserv, in such that it gives me the message (18:39) -BotServ- Syntax: SAY channel text. This is confirmed if I enter /bs say #channel test #channel test2. The module tells me I said "test" in the channel, yet the botserv bot says "test2" in the channel.
How can I continue module execution with the original command rather than the somewhat ripped up one?
Cheers
Phil
-
you cant use strtok() to parse the input.
-
Would you care to enlighten me on what I can use?
That works fine for all my other modules in which they do not have to continue execution.
Cheers
Phil
-
try using myStrGetToken instead, but you will have to give the params to the function as well
quote from anope's wiki
Is strtok() used?
* The use of strtok will often indicate a potential error as strtok is not thread safe, and is used inside of Anope's core.
[Edited on 25-4-2006 by Viper]
-
/**
* Return a copy of the complete last buffer.
* This is needed for modules who cant trust the strtok() buffer, as we dont know who will have already messed about with it.
* @reutrn a pointer to a copy of the last buffer - DONT mess with this, copy if first if you must do things to it.
**/
char *moduleGetLastBuffer(void);
/**
* Will return a malloced copy of the token specified in token_number splitting the string based on dilim. It is the modules responsibility to free() the returned pointer
* @param str String to search in
* @param dilim Character to search for
* @param token_number the token number
* @return token
**/
char *myStrGetToken(const char *str, const char dilim, int token_number);
/**
* Will only return a token if a valid dilimiter is found, i.e. the end of the string dosnt count.
* @param str String to search in
* @param dilim Character to search for
* @param token_number the token number
* @return token
**/
char *myStrGetOnlyToken(const char *str, const char dilim, int token_number);
/**
* Will return from the given token to the end of the string, regardless or other tokens
* @param str String to search in
* @param dilim Character to search for
* @param token_number the token number
* @return token
**/
char *myStrGetTokenRemainder(const char *str, const char dilim,int token_number);
-
Hrmmm, looks like what I need. This is what I came up with, but I feel it is wrong...
char *gettehinfo = moduleGetLastBuffer();
char *curmodchan = myStrGetToken(gettehinfo, " ", 1);
char *saidtext = myStrGetToken(gettehinfo, " ", 2);
I want it to get the 1st and 2nd parameter words.
Cheers
Phil
-
Oh, Ok. Scratch the last point. Checked out cs_disablexop.c and saw the format was slightly wrong. It should have been...
char *curmodchan = myStrGetToken(gettehinfo,' ', 0);
char *saidtext = myStrGetToken(gettehinfo,' ', 2);
What I would be interested to know though, is how I can get every word after a particular point.
E.g. /bs whatever #channel reason for whatever here.
I can get #channel into a variable, but I would also like another variable with "reason for whatever here." in it.
Cheers
Phil
-
/**
* Will return from the given token to the end of the string, regardless or other tokens
* @param str String to search in
* @param dilim Character to search for
* @param token_number the token number
* @return token
**/
char *myStrGetTokenRemainder(const char *str, const char dilim,int token_number);
-
Ah, yes, sorry, I didn't read that fully.
LAST thing (I prommise)
I am trying to get the founder of a channel. From other modules, I have got this...
char *gettehinfo = moduleGetLastBuffer();
char *chan = myStrGetToken(gettehinfo,' ', 0);
ChannelInfo *ci;
char *saidtext = myStrGetTokenRemainder(gettehinfo,' ', 1);
notice(s_BotServ, u->nick, "You have used the Say command in %s saying %s which has the founder %s", chan, saidtext, ci->founder);
Yet, on compile, I get the message:
bs_sayalert.c:44: warning: `ci' might be used uninitialized in this function
Am I doing something wrong?
Cheers
Phil
-
Oh, Slight improvement here...
char *chan = myStrGetToken(gettehinfo,' ', 0);
ChannelInfo *ci;
char *saidtext = myStrGetTokenRemainder(gettehinfo,' ', 1);
char *cifoundernick;
if (ci = cs_findchan(chan)) {
notice(s_BotServ, u->nick, "You have used the Say command in %s saying %s which has the founder %s", chan, saidtext, ci->founder);
}
No errors/crashing services, yet it seems that the ci->founder returns nothing :/
Cheers
Phil
-
you can check http://anope.zero.org/doxy ... all the types are listed there
ci->founder can also be a nickcore i think (if there even is something that returns a founder as char in ci, not sure), so it ll return a reference to an object which will prolly be ignored or so
try ci->founder->display
could be wrong here... it s late and i m not really any gd with c++
[Edited on 25-4-2006 by Viper]
[Edited on 25-4-2006 by Viper]
-
You're a genius! Thanks so much :)