-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.php
executable file
·50 lines (44 loc) · 1.77 KB
/
utils.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
<?php
function powerOf2($n, $name) {
if ($n != 0 && ($n & ($n - 1)) == 0) {
$power = log($n,2);
$MESSAGE_POWER_OF_2 = "🎊🎊<strong>¡¡Enhorabuena $name eres el miembro 2^$power!!</strong> 🎉🎉\nTienes un regalo muy especial a recoger en la guarida de LibreLab 🎁";
return $MESSAGE_POWER_OF_2;
}
return false;
}
function multipleOf50($n, $name) {
if ($n % 50 == 0)
return "<strong>¡Enhorabuena $name, eres el miembro número $n!</strong>\n 🍾 ¡¡Fiesta para todos!! 🍻";
return false;
}
function registerInDatabase($number, $name) {
global $db, $pdo;
$query = "SELECT * FROM MEMBERS_COUNT WHERE number=$number;";
$result = $db->querySingle($query);
if ($result) {
error_log("Number $number already awarded");
return false;
}
if ($result === NULL) {
$comment = "'Miembro $number en chat de LLU'";
$query = $pdo->prepare('INSERT INTO MEMBERS_COUNT (number, winner, comment, delivered) VALUES ( :number, :name, :comment, :delivered )');
$query->execute(array('number' => $number, 'name' => $pdo->quote($name), 'comment' => $comment, 'delivered' => 0));
error_log("Award for no $number member \"$name\"!! ");
return true;
}
// Error in database
error_log('Error in database executing: ' . $query);
return false;
}
function checkReward($number, $name, $chat_id) {
if (!is_int($number)) return;
if ( ($msgPower = powerOf2($number, $name)) && registerInDatabase($number, $name) )
sendMsg($chat_id, $msgPower);
if ( ($msgMultiple = multipleOf50($number, $name)) && registerInDatabase($number, $name) )
sendMsg($chat_id, $msgMultiple);
}
# generic URI format -> scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
function isURIScheme($str) {
return (preg_match('/.+[:\/\/].+/', $str) === 1);
}