[project @ 2005-06-28 09:54:46 by unknown_lamer]
authorunknown_lamer <unknown>
Tue, 28 Jun 2005 09:54:46 +0000 (09:54 +0000)
committerunknown_lamer <unknown>
Tue, 28 Jun 2005 09:54:46 +0000 (09:54 +0000)
Implemented Commands::CTCP and Commands::CTCPReply (for sending CTCP
messages), updated the Parser and ScriptCommands to use
them. Added and documented bot:send-ctcp-reply.

ChangeLog
NEWS
bobot++.info
bobot++.texinfo
source/Commands.C
source/Commands.H
source/Interp.C
source/Message.H
source/Parser.C
source/ScriptCommands.C
source/ScriptCommands.H

index f986ac2..e76f0e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2005-06-28  Clinton Ebadi  <clinton@unknownlamer.org>
+
+       * bobot++.texinfo (Low Level Message Functions): Documented
+       bot:send-ctcp-reply
+
+       * source/Parser.C (parseCTCP): Converted to use Commands::CTCPReply
+
+       * source/Interp.C (interp_init_helper): Bound bot:send-ctcp-reply
+       in scheme
+
+       * bobot++.texinfo (Low Level Message Functions):
+       s/bot:send-CTCP/bot:send-ctcp/
+
+       * source/Interp.C (interp_init_helper): Renamed bot:send-CTCP to
+       bot:send-ctcp
+
+       * source/ScriptCommands.H: Uncommended sendCTCPReply prototype
+
+       * source/ScriptCommands.C (sendCTCP): Convert to use Commands::CTCP
+       (sendCTCPReply): Added
+
+       * source/Parser.C (parseJoin): Convert to use Commands::CTCP
+
+       * source/Commands.C (CTCP): Implemented
+       (CTCPReply): Implemented
+       (Action): Convert to use Commands::CTCP
+
+       * source/Commands.H: Added CTCP (bot, target, command, message)
+       Added CTCPReply (bot, target, command, message)
+
 2005-06-27  Clinton Ebadi  <clinton@unknownlamer.org>
 
        * examples/bot.conf (maxnicklength): Update example config
diff --git a/NEWS b/NEWS
index 01c3d4d..eea086b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,8 @@ Version 2.1.8:
       to the bobot++ functions
     * bot:msg and bot:say may both send to channels and users (instead
       of bot:msg for users and bot:say for channels)
+    * Renamed bot:send-CTCP to bot:send-ctcp
+    * Added bot:send-ctcp-reply to send a ctcp-reply
   + Debugging
     * The debugging evaluator is now enabled when --debug is passed to the bot
 - Documentation
index aebacbb..79bcf70 100644 (file)
@@ -765,7 +765,7 @@ before using these. If you have no idea what these do, read rfc 2812
 (IRC Client Protocol) and CTCP spec. These functions all return
 `*unspecified*' always, so don't use the return value for anything.
 
- -- Function: bot:send-CTCP to command message
+ -- Function: bot:send-ctcp to command message
      `to' is the target of your CTCP message, `command' is the CTCP
      command, and `message' is the message (or arguments) of the
      command. Make sure to `bot:ctcp-quote' the message!
@@ -1093,7 +1093,7 @@ Function Index
                                                               (line 123)
 * bot:say:                               High Level Message Functions.
                                                               (line   7)
-* bot:send-CTCP:                         Low Level Message Functions.
+* bot:send-ctcp:                         Low Level Message Functions.
                                                               (line  13)
 * bot:sent-to-me?:                       Misc Scripting Stuff.
                                                               (line 198)
index 873d00d..1349ce1 100644 (file)
@@ -834,12 +834,20 @@ before using these. If you have no idea what these do, read rfc 2812
 @code{*unspecified*} always, so don't use the return value for
 anything.
 
-@defun bot:send-CTCP to command message
+@defun bot:send-ctcp to command message
 @code{to} is the target of your CTCP message, @code{command} is the
 CTCP command, and @code{message} is the message (or arguments) of the
 command. Make sure to @code{bot:ctcp-quote} the message!
 @end defun
 
+@defun bot:send-ctcp-reply to command message
+@code{to} is the target of your CTCP reply, @code{command} is the
+CTCP command, and @code{message} is the message (or arguments) of the
+command. Make sure to @code{bot:ctcp-quote} the message!
+
+This is used to reply to a ctcp that the bot has received.
+@end defun
+
 @node Misc Scripting Stuff,  , Sending Messages, Scripting
 @section Misc. Scripting Stuff
 
index ba538bb..f222380 100644 (file)
@@ -36,7 +36,7 @@ Commands::Action(Bot *bot, String channel, String message)
   if (message.length() == 0)
     return InvalidParameters;
 
-  QUEUE->sendCTCP (channel, "ACTION", message);
+  Commands::CTCP (bot, channel, "ACTION", message);
 
   return Ok;
 }
@@ -167,6 +167,84 @@ Commands::Ban(Bot *bot, String channel, String who)
   return Ok;
 }
 
+Message
+Commands::CTCP (Bot *bot, std::string target, std::string command,
+               std::string message)
+{
+  CHECK_CONNECTION;
+
+  if (target == "")
+    {
+      return EmptyAddressee;
+    }
+
+  if (command == "")
+    {
+      return InvalidParameters;
+    }
+
+  if (message == "")
+    {
+      return EmptyMessage;
+    }
+
+  if (Utils::channel_p (target) && !CHANNEL (target))
+    {
+      return NotOnChannel (target);
+    }
+
+
+  // Send multi-line messages as seperate privmsgs
+  StringTokenizer st_message (message);
+
+  while (st_message.more_tokens_p ('\n'))
+    {
+      QUEUE->sendCTCP (target, command, st_message.next_token ('\n'));
+    }
+
+  return Ok;
+}
+
+Message
+Commands::CTCPReply (Bot *bot, std::string target, std::string command,
+                    std::string message)
+{
+  CHECK_CONNECTION;
+
+  if (target == "")
+    {
+      return EmptyAddressee;
+    }
+
+  if (command == "")
+    {
+      return InvalidParameters;
+    }
+
+  if (message == "")
+    {
+      return EmptyMessage;
+    }
+
+  // CTCP-REPLY cannot go to a channel
+  if (Utils::channel_p (target))
+    {
+      return NotToChannel;
+    }
+
+
+  // Send multi-line messages as seperate privmsgs
+  StringTokenizer st_message (message);
+
+  while (st_message.more_tokens_p ('\n'))
+    {
+      QUEUE->sendCTCPReply (target, command, st_message.next_token ('\n'));
+    }
+
+  return Ok;
+}
+
+
 Message
 Commands::Cycle(Bot *bot, String channel)
 {
index 2ca3b24..da526c4 100644 (file)
@@ -36,6 +36,8 @@ public:
   static Message AddServer(Bot *, String, String);
   static Message Ban(Bot *, String, String);
   static Message ChangeLevel(Bot *, String, String, int);
+  static Message CTCP (Bot*, std::string, std::string, std::string);
+  static Message CTCPReply (Bot*, std::string, std::string, std::string);
   static Message Cycle(Bot *, String);
   static Message Deban(Bot *, String, String);
   static Message DelServer(Bot *, int);
index 40886ae..94c5045 100644 (file)
@@ -200,8 +200,10 @@ interp_init_helper (void* unused)
                      (SCMFunc)ScriptCommands::sendDCCChatMessage);
 
   // "Low Level" Message functuions
-  scm_c_define_gsubr ("bot:send-CTCP", 3, 0, 0,
+  scm_c_define_gsubr ("bot:send-ctcp", 3, 0, 0,
                      (SCMFunc)ScriptCommands::sendCTCP);
+  scm_c_define_gsubr ("bot:send-ctcp-reply", 3, 0, 0,
+                     (SCMFunc)ScriptCommands::sendCTCPReply);
 }
 
 #undef bot_new_procedure
index b178c99..239051a 100644 (file)
@@ -56,7 +56,7 @@ struct Message {
 #define AlreadyInShitlist(m, mc) (Message(-22, (m) + " is already in shitlist on channel(s) " + (mc)))
 #define EmptyMessage (Message(-23, "Can not send an empty message"))
 #define EmptyAddressee (Message(-24, "Can not send to nobody"))
-#define NotToChannel (Message(-25, "Can not send to a channel. Use \"say\" instead."))
+#define NotToChannel (Message(-25, "Can not send to a channel."))
 #define NotConnected (Message(-26, "Not connected."))
 
 #endif
index 9ea7733..b8eafa3 100644 (file)
@@ -428,8 +428,8 @@ Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
        {
          // This is a part of the antispoof code
          ch->getUser (n)->userkey = Utils::get_key ();
-         cnx->queue->sendCTCP (n, "PING",
-                               ch->getUser (n)->userkey + " " + c);
+         Commands::CTCP (cnx->bot, n, "PING", 
+                         ch->getUser (n)->userkey + " " + c);
        }
     }
 
@@ -830,29 +830,36 @@ Parser::parseCTCP (ServerConnection * cnx,
                                              SCM_UNDEFINED));
 #endif
   if (command == "PING")
-    cnx->queue->sendCTCPReply (nick, "PING", rest);
+    {
+      Commands::CTCPReply (cnx->bot, nick, "PING", rest);
+    }
   else if (command == "VERSION")
     {
-      cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+      Commands::CTCPReply (cnx->bot, nick, "VERSION", 
+                          cnx->bot->versionString);
     }
   else if (command == "CLOCK")
     {
       time_t diff = time (NULL) - cnx->bot->startTime;
-      cnx->queue->sendCTCPReply (nick, "CLOCK",
-                                String ("elapsed time: ") +
-                                String ((long) (diff / 86400)) +
-                                "d" +
-                                String ((long) (diff % 86400) /
-                                        3600) + "h" +
-                                String ((long) (diff % 3600) / 60) +
-                                "m" + String ((long) (diff % 60)) + "s");
+      Commands::CTCPReply (cnx->bot, nick, "CLOCK",
+                          String ("elapsed time: ") +
+                          String ((long) (diff / 86400)) +
+                          "d" +
+                          String ((long) (diff % 86400) /
+                                  3600) + "h" +
+                          String ((long) (diff % 3600) / 60) +
+                          "m" + String ((long) (diff % 60)) + "s");
     }
   else if (command == "COMMAND")
-    cnx->queue->sendCTCPReply (nick,
-                              "COMMAND", String (cnx->bot->commandChar));
+    {
+      Commands::CTCPReply (cnx->bot, nick,
+                          "COMMAND", String (cnx->bot->commandChar));
+    }
   else if (command == "LAG")
-    cnx->queue->sendCTCPReply (nick, "LAG",
-                              String ((long) cnx->lag) + " second(s)");
+    {
+      Commands::CTCPReply (cnx->bot, nick, "LAG",
+                          String ((long) cnx->lag) + " second(s)");
+    }
   else if (command == "DCC")
     {
       StringTokenizer st2 (rest);
index c320f7a..4eb4c72 100644 (file)
@@ -647,12 +647,28 @@ ScriptCommands::sendCTCP(SCM to, SCM command , SCM message)
   VERIFY_STRING(command);
   VERIFY_STRING(message);
 
-  IQUEUE->sendCTCP (Utils::scm2str (to), Utils::scm2str (command),
-                   Utils::scm2str (message));
+  Commands::CTCP (Interp::bot, Utils::scm2str (to), 
+                     Utils::scm2str (command),
+                     Utils::scm2str (message));
 
   return SCM_UNSPECIFIED;
 }
 
+SCM
+ScriptCommands::sendCTCPReply (SCM to, SCM command , SCM message)
+{
+  VERIFY_STRING(to);
+  VERIFY_STRING(command);
+  VERIFY_STRING(message);
+
+  Commands::CTCPReply (Interp::bot, Utils::scm2str (to), 
+                      Utils::scm2str (command),
+                      Utils::scm2str (message));
+
+  return SCM_UNSPECIFIED;
+}
+
+
 SCM
 ScriptCommands::sendNotice (SCM to, SCM message)
 {
index 5643851..689931d 100644 (file)
@@ -83,9 +83,9 @@ public:
   static SCM sendDCCChatMessage (SCM, SCM);
 
   // Message sending
- static SCM sendCTCP(SCM, SCM, SCM);
+  static SCM sendCTCP(SCM, SCM, SCM);
+  static SCM sendCTCPReply(SCM, SCM, SCM);
   /*
-  SCM sendCTCPReply(SCM, SCM, SCM);
   SCM sendChannelMode(SCM);
   SCM sendChannelMode(SCM, SCM, SCM);
   SCM sendInvite(SCM, SCM);