forked from Doomchinchilla/zKillboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zkbBot.php
101 lines (85 loc) · 3.1 KB
/
zkbBot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/* zKillboard
* Copyright (C) 2012-2013 EVE-KILL Team and EVSCO.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$base = __DIR__;
require_once( "config.php" );
require_once( "init.php" );
// zkbBot.php "$nick" "$uhost" "$chan" "$args2"
$nick = $argv[1];
$uhost = $argv[2];
$channel = $argv[3];
$commands = $argv[4];
$params = explode(" ", trim($commands));
$command = $params[0];
array_shift($params);
try {
$fileName = "$base/ircmods/irc_$command.php";
if (!file_exists($fileName)) irc_error("Unknown command: $command");
require_once $fileName;
$className = "irc_$command";
$class = new $className();
if (!is_a($class, "ircCommand")) irc_error("Module $command does not implement interface ircCommand!");
$accessLevel = Db::queryField("select accessLevel from zz_irc_access where name = :name and host = :host", "accessLevel",
array(":name" => $nick, ":host" => $uhost), 0);
if ($accessLevel === null) $accessLevel = 0;
if ($accessLevel < $class->getRequiredAccessLevel()) irc_error("You do not have access to the $command command.");
$params = implode(" ", $params);
$params = trim($params);
$params = explode(" ", $params);
irc_log($nick, $uhost, $command, $params);
$class->execute($nick, $uhost, $channel, $command, $params, $accessLevel);
} catch (Exception $ex) {
irc_error("$command ended with error: " . $ex->getMessage());
}
function irc_log($nick, $uhost, $command, $params)
{
$id = Db::queryField("SELECT id FROM zz_irc_access WHERE name = :nick AND host = :uhost", "id", array(":nick" => $nick, ":uhost" => $uhost));
if ($id == null) $id = 0;
Db::execute("INSERT INTO zz_irc_log (id, nick, command, parameters) VALUES (:id, :nick, :command, :params)", array(":nick" => $nick, ":id" => $id, ":command" => $command, ":params" => implode(" ", $params)));
}
function irc_error($text) {
$text = Log::addIRCColors($text);
irc_out($text);
die();
}
/**
* @param string $text
*/
function irc_out($text) {
global $nick, $channel;
$text = Log::addIRCColors($text);
if ($channel != "#") error_log("PRIVMSG $channel :$nick: $text\n", 3, "/var/killboard/bot/commands.txt");
else error_log("PRIVMSG $nick :$text\n", 3, "/var/killboard/bot/commands.txt");
}
interface ircCommand {
/**
* @return integer
*/
public function getRequiredAccessLevel();
/**
* @return string
*/
public function getDescription();
/**
* @return void
*/
public function execute($nick, $uhost, $channel, $command, $parameters, $nickAccessLevel);
/**
* @return boolean
*/
public function isHidden();
}