- if (crlf == std::string::npos)
- {
- DoCommand(Aliases[i].replace_with, user, safe);
- return 1;
- }
- else
- {
- irc::sepstream commands(Aliases[i].replace_with, '\n');
- std::string command = "*";
- while ((command = commands.GetToken()) != "")
- {
- DoCommand(command, user, safe);
- }
- return 1;
- }
+ /* Stop here if the user is +B and allowbot is set to no. */
+ if (!AllowBots && user->IsModeSet('B'))
+ {
+ return;
+ }
+
+ Channel *c = (Channel *)dest;
+ std::string scommand;
+
+ // text is like "!moo cows bite me", we want "!moo" first
+ irc::spacesepstream ss(text);
+ ss.GetToken(scommand);
+ irc::string fcommand = scommand.c_str();
+
+ if (fcommand.empty())
+ {
+ return; // wtfbbq
+ }
+
+ // we don't want to touch non-fantasy stuff
+ if (*fcommand.c_str() != fprefix)
+ {
+ return;
+ }
+
+ // nor do we give a shit about the prefix
+ fcommand.erase(fcommand.begin());
+
+ std::multimap<irc::string, Alias>::iterator i = Aliases.find(fcommand);
+
+ if (i == Aliases.end())
+ return;
+
+ /* Avoid iterating on to other aliases if no patterns match */
+ std::multimap<irc::string, Alias>::iterator upperbound = Aliases.upper_bound(fcommand);
+
+
+ /* The parameters for the command in their original form, with the command stripped off */
+ std::string compare = text.substr(fcommand.length() + 1);
+ while (*(compare.c_str()) == ' ')
+ compare.erase(compare.begin());
+
+ while (i != upperbound)
+ {
+ if (i->second.ChannelCommand)
+ {
+ // We use substr(1) here to remove the fantasy prefix
+ if (DoAlias(user, c, &(i->second), compare, text.substr(1)))
+ return;