Add gnulib gettext module for config.rpath
[clinton/bobotpp.git] / source / BotInterp.H
CommitLineData
cb21075d 1// BotInterp.H -*- C++ -*-
2// Copyright (c) 1998 Etienne BERNARD
3c37f9a8 3// Copyright (C) 2002,2005,2008 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
3c37f9a8 29#include <functional>
7a9d1172 30#include <list>
31#include <map>
32#include <string>
3c37f9a8 33
cfa82921 34#include <ctime>
35
cb21075d 36#include <libguile.h>
3c37f9a8 37
38#include "BotThreading.H"
cb21075d 39#include "String.H"
3c37f9a8 40#include "Utils.H"
cb21075d 41
42class Bot;
43
44struct Hook {
45 int type;
46 int priority;
47 bool fallthru;
48
7a9d1172 49 std::string regex_str;
50 std::string name;
cb21075d 51 SCM regex;
52 SCM function;
53
7a9d1172 54 Hook(int t, std::string rs, SCM r, SCM f, int p, bool ft, std::string n="DEFAULT")
31433d27 55 : type(t), priority (p), fallthru (ft), regex_str(rs),
fd7440f1 56 name (n), regex(r), function(f) { }
cb21075d 57
2d3af8a4 58 bool operator< (const Hook & h) const;
cb21075d 59
60 enum {
61 ACTION, NICKNAME, SIGNOFF, CTCP, CTCP_REPLY,
ae97d6ec 62 DISCONNECT, FLOOD, INVITE, JOIN, KICK, MODE,
63 MESSAGE, NAMES, NOTICE, PART, PUBLIC,
fed59248 64 PUBLIC_NOTICE, RAW, TIMER, TOPIC,
65 // send hooks
6530edbf 66 SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE,
528799bd 67 SEND_WHO, SEND_WHOIS,
6530edbf 68 // DCC hooks
133eff7a 69 DCC_CHAT_BEGIN, DCC_CHAT_END, DCC_CHAT_MESSAGE
cb21075d 70 };
71};
72
73struct Timer {
74 int count;
75 std::time_t when;
76 SCM function;
77
78 Timer(int c, std::time_t t, SCM f)
79 : count(c), when(t), function(f) { }
3c37f9a8 80
81 bool operator< (const Timer & other) const
82 { return when < other.when; }
cb21075d 83};
84
85class BotInterp {
3c37f9a8 86 typedef std::list<Timer *> TimerList;
7a9d1172 87 typedef std::list<Hook *> HookList;
88 typedef std::map<int, HookList, std::less<int> > HookMap;
3c37f9a8 89
cb21075d 90 Bot * bot;
91 SCM logPort;
7a9d1172 92 int counter;
93
94 HookMap hooks;
3c37f9a8 95 TimerList timers;
7a9d1172 96
3c37f9a8 97 Utils::IndirectPred<Timer, std::less<Timer> > timer_sort_p;
7a9d1172 98 Utils::IndirectPred<Hook, std::less<Hook> > hook_sort_p;
99
3c37f9a8 100 BotMutex hook_mutex;
101 BotMutex timer_mutex; // NOTE: recursive lock
cb21075d 102
103public:
104 BotInterp(Bot *, String);
105
d56bdd22 106 SCM ScriptLog();
cb21075d 107
108 void Execute(String);
109 void LoadScript(String);
110
7a9d1172 111 bool AddHook(int, SCM, SCM, int, bool, std::string);
112 bool RunHooks(int, std::string, SCM);
cb21075d 113
114 SCM AddTimer(int, SCM);
115 bool DelTimer(SCM);
116 bool RunTimers(int);
117
118 friend class Interp;
119 friend class ScriptCommands;
120};
121
122#endif
123#endif