[project @ 2002-08-02 04:31:30 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;
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)
51 return true;
52 else if (priority > h.priority)
53 return false;
54 else if (fallthru && h.fallthru)
55 return false;
cb21075d 56 else if (fallthru && !h.fallthru)
57 return false;
58 else if (!fallthru && h.fallthru)
59 return true;
cb21075d 60 }
61
62 enum {
63 ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY,
64 DISCONNECT, FLOOD, INVITE, JOIN, KICK, LEAVE,
65 MODE, MESSAGE, NAMES, NOTICE, PUBLIC,
66 PUBLIC_NOTICE, RAW, TIMER, TOPIC
67 };
68};
69
70struct Timer {
71 int count;
72 std::time_t when;
73 SCM function;
74
75 Timer(int c, std::time_t t, SCM f)
76 : count(c), when(t), function(f) { }
77};
78
79class BotInterp {
80 Bot * bot;
81 SCM logPort;
82 std::map<int, std::list<Hook *>, std::less<int> > hooksMap;
83 std::list<Timer *> timersList;
84 int counter;
85
86public:
87 BotInterp(Bot *, String);
88
89 void ScriptLog(SCM);
90
91 void Execute(String);
92 void LoadScript(String);
93
fd7440f1 94 bool AddHook(int, SCM, SCM, int, bool, String);
cb21075d 95 bool RunHooks(int, String, SCM);
96
97 SCM AddTimer(int, SCM);
98 bool DelTimer(SCM);
99 bool RunTimers(int);
100
101 friend class Interp;
102 friend class ScriptCommands;
103};
104
105#endif
106#endif