cb21075d |
1 | // BotInterp.H -*- C++ -*- |
2 | // Copyright (c) 1998 Etienne BERNARD |
3 | // Copyright (C) 2002 Clinton Ebadi |
4 | |
5 | // This program is free software; you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation; either version 2 of the License, or |
8 | // (at your option) any later version. |
9 | |
10 | // This program is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with this program; if not, write to the Free Software |
39b022cb |
17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cb21075d |
18 | |
19 | #ifndef BOTINTERP_H |
20 | #define BOTINTERP_H |
21 | |
22 | #ifdef HAVE_CONFIG_H |
23 | #include "config.h" |
24 | #endif |
25 | |
26 | #ifdef USESCRIPTS |
27 | |
28 | #include <ctime> |
29 | #include <libguile.h> |
30 | #include "String.H" |
31 | |
32 | class Bot; |
33 | |
34 | struct Hook { |
35 | int type; |
36 | int priority; |
37 | bool fallthru; |
38 | |
39 | String regex_str; |
fd7440f1 |
40 | String name; |
cb21075d |
41 | SCM regex; |
42 | SCM function; |
43 | |
fd7440f1 |
44 | Hook(int t, String rs, SCM r, SCM f, int p, bool ft, String n="DEFAULT") |
31433d27 |
45 | : type(t), priority (p), fallthru (ft), regex_str(rs), |
fd7440f1 |
46 | name (n), regex(r), function(f) { } |
cb21075d |
47 | |
48 | bool operator< (const Hook &h) const |
49 | { |
be3612f3 |
50 | if (priority < h.priority) |
cf8ea873 |
51 | { |
52 | return true; |
53 | } |
be3612f3 |
54 | else if (priority > h.priority) |
cf8ea873 |
55 | { |
56 | return false; |
57 | } |
be3612f3 |
58 | else if (fallthru && h.fallthru) |
cf8ea873 |
59 | { |
60 | return false; |
61 | } |
cb21075d |
62 | else if (fallthru && !h.fallthru) |
cf8ea873 |
63 | { |
64 | return false; |
65 | } |
cb21075d |
66 | else if (!fallthru && h.fallthru) |
cf8ea873 |
67 | { |
68 | return true; |
69 | } |
70 | else |
71 | { |
72 | // NOTE: This should never be reached |
73 | return false; |
74 | } |
cb21075d |
75 | } |
76 | |
77 | enum { |
78 | ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY, |
79 | DISCONNECT, FLOOD, INVITE, JOIN, KICK, LEAVE, |
80 | MODE, MESSAGE, NAMES, NOTICE, PUBLIC, |
fed59248 |
81 | PUBLIC_NOTICE, RAW, TIMER, TOPIC, |
82 | // send hooks |
6530edbf |
83 | SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE, |
84 | // DCC hooks |
85 | DCC_CHAT_BEGIN, DCC_CHAT_MESSAGE |
cb21075d |
86 | }; |
87 | }; |
88 | |
89 | struct Timer { |
90 | int count; |
91 | std::time_t when; |
92 | SCM function; |
93 | |
94 | Timer(int c, std::time_t t, SCM f) |
95 | : count(c), when(t), function(f) { } |
96 | }; |
97 | |
98 | class BotInterp { |
99 | Bot * bot; |
100 | SCM logPort; |
101 | std::map<int, std::list<Hook *>, std::less<int> > hooksMap; |
102 | std::list<Timer *> timersList; |
103 | int counter; |
104 | |
105 | public: |
106 | BotInterp(Bot *, String); |
107 | |
d56bdd22 |
108 | SCM ScriptLog(); |
cb21075d |
109 | |
110 | void Execute(String); |
111 | void LoadScript(String); |
112 | |
fd7440f1 |
113 | bool AddHook(int, SCM, SCM, int, bool, String); |
cb21075d |
114 | bool RunHooks(int, String, SCM); |
115 | |
116 | SCM AddTimer(int, SCM); |
117 | bool DelTimer(SCM); |
118 | bool RunTimers(int); |
119 | |
120 | friend class Interp; |
121 | friend class ScriptCommands; |
122 | }; |
123 | |
124 | #endif |
125 | #endif |