[project @ 2005-07-07 21:19:26 by unknown_lamer]
[clinton/bobotpp.git] / source / BotInterp.H
CommitLineData
cb21075d 1// BotInterp.H -*- C++ -*-
2// Copyright (c) 1998 Etienne BERNARD
528799bd 3// Copyright (C) 2002,2005 Clinton Ebadi
cb21075d 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
528799bd 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18// 02110-1301, USA.
cb21075d 19
20#ifndef BOTINTERP_H
21#define BOTINTERP_H
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#ifdef USESCRIPTS
28
29#include <ctime>
30#include <libguile.h>
31#include "String.H"
32
33class Bot;
34
35struct Hook {
36 int type;
37 int priority;
38 bool fallthru;
39
40 String regex_str;
fd7440f1 41 String name;
cb21075d 42 SCM regex;
43 SCM function;
44
fd7440f1 45 Hook(int t, String rs, SCM r, SCM f, int p, bool ft, String n="DEFAULT")
31433d27 46 : type(t), priority (p), fallthru (ft), regex_str(rs),
fd7440f1 47 name (n), regex(r), function(f) { }
cb21075d 48
49 bool operator< (const Hook &h) const
50 {
be3612f3 51 if (priority < h.priority)
cf8ea873 52 {
53 return true;
54 }
be3612f3 55 else if (priority > h.priority)
cf8ea873 56 {
57 return false;
58 }
be3612f3 59 else if (fallthru && h.fallthru)
cf8ea873 60 {
61 return false;
62 }
cb21075d 63 else if (fallthru && !h.fallthru)
cf8ea873 64 {
65 return false;
66 }
cb21075d 67 else if (!fallthru && h.fallthru)
cf8ea873 68 {
69 return true;
70 }
71 else
72 {
73 // NOTE: This should never be reached
74 return false;
75 }
cb21075d 76 }
77
78 enum {
79 ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY,
ae97d6ec 80 DISCONNECT, FLOOD, INVITE, JOIN, KICK, MODE,
81 MESSAGE, NAMES, NOTICE, PART, PUBLIC,
fed59248 82 PUBLIC_NOTICE, RAW, TIMER, TOPIC,
83 // send hooks
6530edbf 84 SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE,
528799bd 85 SEND_WHO, SEND_WHOIS,
6530edbf 86 // DCC hooks
133eff7a 87 DCC_CHAT_BEGIN, DCC_CHAT_END, DCC_CHAT_MESSAGE
cb21075d 88 };
89};
90
91struct Timer {
92 int count;
93 std::time_t when;
94 SCM function;
95
96 Timer(int c, std::time_t t, SCM f)
97 : count(c), when(t), function(f) { }
98};
99
100class BotInterp {
101 Bot * bot;
102 SCM logPort;
103 std::map<int, std::list<Hook *>, std::less<int> > hooksMap;
104 std::list<Timer *> timersList;
105 int counter;
106
107public:
108 BotInterp(Bot *, String);
109
d56bdd22 110 SCM ScriptLog();
cb21075d 111
112 void Execute(String);
113 void LoadScript(String);
114
fd7440f1 115 bool AddHook(int, SCM, SCM, int, bool, String);
cb21075d 116 bool RunHooks(int, String, SCM);
117
118 SCM AddTimer(int, SCM);
119 bool DelTimer(SCM);
120 bool RunTimers(int);
121
122 friend class Interp;
123 friend class ScriptCommands;
124};
125
126#endif
127#endif