[project @ 2002-07-08 21:11:15 by unknown_lamer]
[clinton/bobotpp.git] / source / BotInterp.H
CommitLineData
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
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
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
32class Bot;
33
34struct Hook {
35 int type;
36 int priority;
37 bool fallthru;
38
39 String regex_str;
40 SCM regex;
41 SCM function;
42
43 Hook(int t, String rs, SCM r, SCM f, int p, bool ft)
31433d27 44 : type(t), priority (p), fallthru (ft), regex_str(rs),
45 regex(r), function(f) { }
cb21075d 46
47 bool operator< (const Hook &h) const
48 {
49 if (fallthru && h.fallthru)
50 return priority < h.priority;
51 // fallthru-thru is > non-fallthru thru ALWAYS
52 else if (fallthru && !h.fallthru)
53 return false;
54 else if (!fallthru && h.fallthru)
55 return true;
56 else
57 return priority < h.priority;
58 }
59
60 enum {
61 ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY,
62 DISCONNECT, FLOOD, INVITE, JOIN, KICK, LEAVE,
63 MODE, MESSAGE, NAMES, NOTICE, PUBLIC,
64 PUBLIC_NOTICE, RAW, TIMER, TOPIC
65 };
66};
67
68struct Timer {
69 int count;
70 std::time_t when;
71 SCM function;
72
73 Timer(int c, std::time_t t, SCM f)
74 : count(c), when(t), function(f) { }
75};
76
77class BotInterp {
78 Bot * bot;
79 SCM logPort;
80 std::map<int, std::list<Hook *>, std::less<int> > hooksMap;
81 std::list<Timer *> timersList;
82 int counter;
83
84public:
85 BotInterp(Bot *, String);
86
87 void ScriptLog(SCM);
88
89 void Execute(String);
90 void LoadScript(String);
91
92 bool AddHook(int, SCM, SCM, int, bool);
93 bool RunHooks(int, String, SCM);
94
95 SCM AddTimer(int, SCM);
96 bool DelTimer(SCM);
97 bool RunTimers(int);
98
99 friend class Interp;
100 friend class ScriptCommands;
101};
102
103#endif
104#endif