From 133eff7a2375d1992654e67ec3ff03ab53cd92fe Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Mon, 4 Jul 2005 08:15:08 +0000 Subject: [PATCH] [project @ 2005-07-04 08:15:08 by unknown_lamer] hooks/dcc/chat-end is now called when a chat is killed for being idle, and when a chat is closed by the user on the other end. It was also documented. --- ChangeLog | 17 +++++++++++++++++ TODO | 2 +- bobot++.info | 29 +++++++++++++++++++---------- bobot++.texinfo | 9 +++++++++ scripts/bobot-utils.scm | 4 ++-- source/Bot.C | 3 ++- source/BotInterp.H | 2 +- source/DCCConnection.H | 3 ++- source/DCCManager.C | 31 +++++++++++++++++++++++++++++-- source/DCCParser.C | 10 ++++++---- source/Interp.C | 2 ++ source/ServerQueue.H | 3 ++- 12 files changed, 92 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8af66ea..a2aaca2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-07-04 Clinton Ebadi + + * source/DCCManager.C (checkInput): + + * scripts/bobot-utils.scm (bot:log): Updated to use bot:logport + instead of bot-logport + + * source/Interp.C (interp_init_helper): Add hooks/dcc/chat-end + constant to Scheme + + * bobot++.texinfo (DCC CHAT Hooks): Document hooks/dcc/chat-end + + * source/BotInterp.H: Add DCC_CHAT_END to enum + + * source/DCCManager.C (checkStale): Run hooks/dcc/chat-end when + deleting a stale connection. + 2005-07-03 Clinton Ebadi * bobot++.texinfo (Hook Types): Documented all hooks diff --git a/TODO b/TODO index 5ff87a4..ced8d56 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,7 @@ Done: * Utils::valid_nickname_p should have a configurable max nick length * More detailed script error reporting * Commands::sendCTCP, Commands::sendCTCPReply +* Add DCC_CHAT_END hook for Scheme 2.2: * Finish Texinfo manual @@ -16,7 +17,6 @@ Done: (e.g. bot:send-CTCP to send a CTCP message) * Add util functions for doing stuff like quoting CTCP messages * Finish adding hooks/send hooks -* Add DCC_CHAT_END hook for Scheme 2.4: * Use configuration database class diff --git a/bobot++.info b/bobot++.info index 912e273..5883a10 100644 --- a/bobot++.info +++ b/bobot++.info @@ -852,6 +852,14 @@ bot receives messages from the user in a DCC CHAT. This hook is called when a user begins a DCC CHAT with the bot. FROM is the user's address in the form `nick!user@host'. + -- Function: hooks/dcc/chat-end address + This hook is called when a DCC CHAT is purged after being idle for + a while, or when the user closes the DCC CHAT. As such, you cannot + write any more data to the DCC CHAT. + + ADDRESS is the address (nick!user@host) of the person on the other + side of the DCC. + -- Function: hooks/dcc/chat-message from message This hook is called when a user sends a message to the bot through a DCC CHAT. @@ -1316,7 +1324,8 @@ Function Index * hooks/ctcp-reply: Received Message Hooks. (line 43) * hooks/dcc/chat-begin: DCC CHAT Hooks. (line 10) -* hooks/dcc/chat-message: DCC CHAT Hooks. (line 14) +* hooks/dcc/chat-end: DCC CHAT Hooks. (line 14) +* hooks/dcc/chat-message: DCC CHAT Hooks. (line 22) * hooks/disconnect: Received Message Hooks. (line 54) * hooks/flood: Miscellaneous Hooks. (line 7) @@ -1397,14 +1406,14 @@ Node: Hook Types22621 Node: Received Message Hooks23185 Node: Sent Message Hooks28412 Node: DCC CHAT Hooks29809 -Node: Miscellaneous Hooks30526 -Node: Scheme User Levels30975 -Node: Sending Messages32109 -Node: High Level Message Functions32725 -Node: Low Level Message Functions33505 -Node: Misc Scripting Stuff34568 -Node: Concept Index41144 -Node: Function Index41363 -Node: Variable Index52526 +Node: Miscellaneous Hooks30849 +Node: Scheme User Levels31298 +Node: Sending Messages32432 +Node: High Level Message Functions33048 +Node: Low Level Message Functions33828 +Node: Misc Scripting Stuff34891 +Node: Concept Index41467 +Node: Function Index41686 +Node: Variable Index52922  End Tag Table diff --git a/bobot++.texinfo b/bobot++.texinfo index 767a859..47f1d53 100644 --- a/bobot++.texinfo +++ b/bobot++.texinfo @@ -904,6 +904,15 @@ This hook is called when a user begins a DCC CHAT with the bot. @var{from} is the user's address in the form @samp{nick!user@@host}. @end defun +@defun hooks/dcc/chat-end address +This hook is called when a DCC CHAT is purged after being idle for a +while, or when the user closes the DCC CHAT. As such, you cannot write +any more data to the DCC CHAT. + +@var{address} is the address (nick!user@@host) of the person on the +other side of the DCC. +@end defun + @defun hooks/dcc/chat-message from message This hook is called when a user sends a message to the bot through a DCC CHAT. diff --git a/scripts/bobot-utils.scm b/scripts/bobot-utils.scm index 4f7b6d1..b9d6b66 100644 --- a/scripts/bobot-utils.scm +++ b/scripts/bobot-utils.scm @@ -25,8 +25,8 @@ (for-each (lambda (x) (if (thunk? x) - (display (x) (bot-logport)) - (display x (bot-logport)))) + (display (x) (bot:logport)) + (display x (bot:logport)))) messages) (bot:flushport)) diff --git a/source/Bot.C b/source/Bot.C index 64b4e46..8a38d01 100644 --- a/source/Bot.C +++ b/source/Bot.C @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. #include #include diff --git a/source/BotInterp.H b/source/BotInterp.H index 4ce1a2f..959a172 100644 --- a/source/BotInterp.H +++ b/source/BotInterp.H @@ -82,7 +82,7 @@ struct Hook { // send hooks SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE, // DCC hooks - DCC_CHAT_BEGIN, DCC_CHAT_MESSAGE + DCC_CHAT_BEGIN, DCC_CHAT_END, DCC_CHAT_MESSAGE }; }; diff --git a/source/DCCConnection.H b/source/DCCConnection.H index c203b8f..916add9 100644 --- a/source/DCCConnection.H +++ b/source/DCCConnection.H @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. #ifndef DCCCONNECTION_H #define DCCCONNECTION_H diff --git a/source/DCCManager.C b/source/DCCManager.C index caf855d..2437fea 100644 --- a/source/DCCManager.C +++ b/source/DCCManager.C @@ -1,5 +1,5 @@ // DCCManager.H -*- C++ -*- -// Copyright (c) 2002 Clinton Ebadi +// Copyright (c) 2002,2005 Clinton Ebadi // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -13,9 +13,11 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. #include "DCCManager.H" +#include "Utils.H" void DCCManager::addConnection (DCCConnection *cnx) @@ -57,6 +59,18 @@ DCCManager::checkStale () if (temp_cnx->get_autoRemove () && std::time (0) >= (std::time_t)(temp_cnx->get_lastSpoken () + Bot::DCC_DELAY)) { +#ifdef USESCRIPTS + DCCPerson *dp = new DCCPerson ((DCCConnection *) temp_cnx); + + // run hooks/dcc/chat-end + dp->bot->botInterp->RunHooks + (Hook::DCC_CHAT_END, + dp->getAddress (), + scm_list_n (Utils:: + str2scm (dp->getAddress ()), + SCM_UNDEFINED)); + delete dp; +#endif delete it->second; dcc_map.erase (it); } @@ -86,6 +100,19 @@ DCCManager::checkInput (fd_set rd) { if (it2->second->handleInput()) { +#ifdef USESCRIPTS + DCCPerson *dp = new DCCPerson (*it2->second); + + // run hooks/dcc/chat-end + dp->bot->botInterp->RunHooks + (Hook::DCC_CHAT_END, + dp->getAddress (), + scm_list_n (Utils:: + str2scm (dp->getAddress ()), + SCM_UNDEFINED)); + delete dp; +#endif + delete it2->second->dcc; delete it2->second; dcc_map.erase(it2); diff --git a/source/DCCParser.C b/source/DCCParser.C index f0028a9..6ca0fa8 100644 --- a/source/DCCParser.C +++ b/source/DCCParser.C @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. #ifdef HAVE_CONFIG_H #include "config.h" @@ -34,9 +35,10 @@ DCCParser::parseLine(DCCConnection *cnx, String line) // Call hooks/dcc/chat-message hook functions cnx->get_bot()->botInterp->RunHooks (Hook::DCC_CHAT_MESSAGE, from->getAddress () + " " + line, - scm_list_n (Utils::str2scm (from->getAddress ()), - Utils::str2scm (line), - SCM_UNDEFINED)); + scm_list_n + (Utils::str2scm (from->getAddress ()), + Utils::str2scm (line), + SCM_UNDEFINED)); #endif Parser::parseMessage(cnx->get_bot()->serverConnection, from, cnx->get_bot()->nickName, diff --git a/source/Interp.C b/source/Interp.C index 161b89f..27ad0fb 100644 --- a/source/Interp.C +++ b/source/Interp.C @@ -168,6 +168,8 @@ interp_init_helper (void* unused) // dcc hooks scm_c_define ("hooks/dcc/chat-begin", scm_long2num (Hook::DCC_CHAT_BEGIN)); + scm_c_define ("hooks/dcc/chat-end", + scm_long2num (Hook::DCC_CHAT_END)); scm_c_define ("hooks/dcc/chat-message", scm_long2num (Hook::DCC_CHAT_MESSAGE)); diff --git a/source/ServerQueue.H b/source/ServerQueue.H index 8881ec9..399a9ce 100644 --- a/source/ServerQueue.H +++ b/source/ServerQueue.H @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. #ifndef SERVERQUEUE_H #define SERVERQUEUE_H -- 2.20.1