-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.php
137 lines (136 loc) · 3.5 KB
/
lib.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
function checkC ($who, $command) {
global $admin;
global $mods;
global $C_User;
global $C_Message;
global $triggerD;
global $triggerE;
if (isset($triggerE[$command]) && !empty($triggerE[$command])) {
$trigger = $triggerE[$command];
} else {
$trigger = $triggerD;
}
switch($who) {
case "all":
if (explode(" ", trim($C_Message))[0] == $trigger.$command) {
return true;
}
case "mods":
foreach ($mods as $mod) {
if (explode(" ", trim($C_Message))[0] == $trigger.$command && strtolower($C_User) == strtolower($mod)) {
return true;
}
}
case "admin":
if (explode(" ", trim($C_Message))[0] == $trigger.$command && strtolower($C_User) == strtolower($admin)) {
return true;
}
case "none":
return false;
}
}
function secondsToTimeString ($sec) {
$days = floor($sec / 86400);
$hours= floor($sec / 3600 % 60 % 60 % 24);
$mins = floor($sec / 60 % 60);
$secs = floor($sec % 60);
$time = "";
if ($days >= 2) {
$time .= $days." days";
} elseif ($days >= 1) {
$time .= $days." day";
}
if ($days >= 1 && (($hours >= 1 && $mins >= 1) || ($hours >= 1 && $secs >= 1) || ($mins >= 1 && $secs >= 1))) {
$time .= ", ";
} elseif ($days >= 1 && ($hours >= 1 || $mins >= 1 || $secs >= 1)) {
$time .= " and ";
}
if ($hours >= 2) {
$time .= $hours." hours";
} elseif ($hours >= 1) {
$time .= $hours." hour";
}
if ($hours >= 1 && $mins >= 1 && $secs >= 1) {
$time .= ", ";
} elseif ($hours >= 1 && ($mins >= 1 || $secs >= 1)) {
$time .= " and ";
}
if ($mins >= 2) {
$time .= $mins." minutes";
} elseif ($mins >= 1) {
$time .= $mins." minute";
}
if ($mins >= 1 && $secs >= 1) {
$time .= " and ";
}
if ($secs >= 2) {
$time .= $secs." seconds";
} elseif ($secs >= 1) {
$time .= $secs." second";
}
return $time;
}
function checkIfMod ($channel, $nick) {
$cAPI = ltrim($channel, '#');
$cAPIChat = json_decode(@file_get_contents("http://tmi.twitch.tv/group/user/".$cAPI."/chatters"));
if (isset($cAPIChat) && !empty($cAPIChat)) {
$modInChat = $cAPIChat->chatters->moderators;
foreach ($modInChat as $modInChat) {
if ($modInChat == $nick) {
return true;
}
}
} else {
echo "\nCouldn't connect to Twitch API!";
}
return false;
}
function checkCurrentGame ($channel) {
$cAPIGame = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.$channel));
$curGame = nl2br($cAPIGame->stream->channel->game);
return $curGame;
}
function updateList (){
global $coms;
global $pathIs;
global $isMod;
global $mods;
global $channel;
global $nick;
global $isTwitch;
global $server;
global $host;
global $port;
global $admin;
global $triggerD;
global $triggerE;
global $ghostMode;
global $channel;
global $name;
global $nick;
global $pass;
include $pathIs."/config.php";
if (!file_exists($pathIs."/mods.txt")) {
touch($pathIs."/mods.txt");
}
if (!file_exists($pathIs."/nokill.txt")) {
touch($pathIs."/nokill.txt");
}
echo "\n=> !update -> Done";
$coms = glob($pathIs.'/commands/*.{php}', GLOB_BRACE);
if ($isTwitch) {
$isMod = checkIfMod($channel, $nick);
} else {
$isMod = false;
}
$mods = file($pathIs.'/mods.txt', FILE_IGNORE_NEW_LINES);
}
function isValidName ($ee) {
if(preg_match('/[^A-Za-z0-9\-_]/', $ee)>0) {
return false;
} else {
return true;
}
}
?>