-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc_functions.php
90 lines (85 loc) · 3.11 KB
/
misc_functions.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
<?php
namespace CluebotNG;
/*
* Copyright (C) 2015 Jacobi Carter and Chris Breneman
*
* This file is part of ClueBot NG.
*
* ClueBot NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ClueBot NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
function myfnmatch($pattern, $string)
{
if (strlen($string) < 4000) {
return fnmatch($pattern, $string);
} else {
$pattern = strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.', '\[' => '[', '\]' => ']'));
if (preg_match('#^' . $pattern . '$#', $string)) {
return true;
}
return false;
}
}
function loadHuggleWhitelist()
{
global $logger;
if (($hgWLRaw = @file_get_contents('https://huggle.bena.rocks/?action=read&wp=en.wikipedia.org')) != null) {
Globals::$wl = array_slice(explode('|', $hgWLRaw), 0, -1);
$logger->addInfo('Loaded huggle whitelist (' . count(Globals::$wl) . ')');
} else {
$logger->addWarning('Failed to load huggle whitelist');
}
}
function doInit()
{
global $logger;
if (Config::$pass == null) {
Config::$pass = trim(file_get_contents(getenv('HOME') . '/.cluebotng.bot.password'));
}
Api::init($logger);
if (!Api::$a->login(Config::$user, Config::$pass)) {
$logger->addError('Failed to authenticate');
die();
}
Globals::$atime = time();
Globals::$tfas = 0;
Globals::$stdin = fopen('php://stdin', 'r');
Globals::$run = Api::$q->getpage('User:' . Config::$user . '/Run');
Globals::$optin = Api::$q->getpage('User:' . Config::$user . '/Optin');
Globals::$aoptin = Api::$q->getpage('User:' . Config::$user . '/AngryOptin');
loadHuggleWhitelist();
Globals::$stalk = array();
Globals::$edit = array();
$tmp = explode("\n", Api::$q->getpage('User:' . Config::$owner . '/CBAutostalk.js'));
foreach ($tmp as $tmp2) {
if (strlen($tmp2) > 0 && substr($tmp2, 0, 1) != '#') {
$tmp3 = explode('|', $tmp2, 2);
if (count($tmp3) == 2) {
Globals::$stalk[$tmp3[0]] = trim($tmp3[1]);
} else {
$logger->addInfo("Skipping auto stalk entry: $tmp2");
}
}
}
$tmp = explode("\n", Api::$q->getpage('User:' . Config::$owner . '/CBAutoedit.js'));
foreach ($tmp as $tmp2) {
if (strlen($tmp2) > 0 && substr($tmp2, 0, 1) != '#') {
$tmp3 = explode('|', $tmp2, 2);
if (count($tmp3) == 2) {
Globals::$edit[$tmp3[0]] = trim($tmp3[1]);
} else {
$logger->addInfo("Skipping auto edit entry: $tmp2");
}
}
}
}