-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
145 lines (131 loc) · 3.56 KB
/
bot.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
138
139
140
141
142
143
144
145
<?php
/**
* telegram Zufallbot
*
* @author RundesBalli <webspam@rundesballi.com>
* @copyright 2020 RundesBalli
* @see https://github.com/RundesBalli/telegram-Zufallbot
* @version 1.0
* @license MIT-License
*/
/**
* Einbinden der Konfigurationsdatei.
*/
require_once(__DIR__.DIRECTORY_SEPARATOR."config.php");
/**
* Einbinden der Funktionsdatei.
*/
require_once(__DIR__.DIRECTORY_SEPARATOR."functions.php");
/**
* Zeitzone
*/
date_default_timezone_set("Europe/Berlin");
/**
* Input von Telegram auffangen.
*/
$content = file_get_contents("php://input");
$response = json_decode($content, true);
if(empty($response)) {
die();
}
/**
* Emoji-Konstanten
*/
const EMOJI_DICE = "\xF0\x9F\x8E\xB2";
const EMOJI_NUMBERS = "\xF0\x9F\x94\xA2";
const EMOJI_LETTERS = "\xF0\x9F\x94\xA0";
const EMOJI_THUMBSUP = "\xF0\x9F\x91\x8D";
const EMOJI_THUMBSDOWN = "\xF0\x9F\x91\x8E";
const EMOJI_INFORMATION = "\xE2\x84\xB9";
const EMOJI_TICKET = "\xF0\x9F\x8E\xAB";
/**
* Hilfetext
*/
$helptext = EMOJI_DICE." *Zufallbot-Befehle:* ".EMOJI_DICE."\n".
"/hilfe - zeigt diese Hilfe an\n".
"\n".
EMOJI_NUMBERS." *Zufallszahlen:*\n".
"/z - 1-100\n".
"/z6 - 1-6\n".
"/z10 - 1-10\n".
"/z`xxx` - 1-`xxx`\n".
"\n".
EMOJI_THUMBSUP." ".EMOJI_THUMBSDOWN." *Ja oder Nein:*\n".
"/jn\n".
"\n".
EMOJI_LETTERS." *Buchstaben:*\n".
"/b - A-Z\n".
"\n".
EMOJI_TICKET." *Lotteriezahlen:*\n".
"/l - Lottozahlen, 6 aus 49\n".
"/ej - Eurojackpot, 5 aus 50, 2 aus 10\n".
"\n".
EMOJI_INFORMATION." *Infos:*\n".
"Bot erstellt von [RundesBalli.com](https://RundesBalli.com).\n".
"Quellcode bei [GitHub](https://github.com/RundesBalli/telegram-Zufallbot).";
/**
* Prüfung der Eingabe und matchen des übergebenen Befehls.
*/
if(preg_match("/\/(?'action'hilfe|jn|z(?=(?'range'[1-9]\d{1,9}|[2-9]))?|b|start|l|ej)/i", $response['message']['text'], $match) !== 1) {
SendMessageToTelegram($helptext, $response['message']['chat']['id'], TRUE);
die();
}
$action = $match['action'];
/**
* Generiere Zufallszahl
*
* Wenn keine Range übergeben wurde oder diese ungültig war, dann wird eine Zahl zwischen 1 und 100 ausgegeben
*/
if($action == "z") {
SendMessageToTelegram(random_int(1, (empty($match['range']) ? 100 : intval($match['range']))), $response['message']['chat']['id'], TRUE);
die();
}
/**
* Generiere zufälligen Buchstaben
* ASCII65 (großes A) bis ASCII90 (großes Z)
*/
if($action == "b") {
SendMessageToTelegram(chr(random_int(65, 90)), $response['message']['chat']['id'], TRUE);
die();
}
/**
* Hilfetext bei "start" oder "hilfe"
*/
if($action == "hilfe" OR $action == "start") {
SendMessageToTelegram($helptext, $response['message']['chat']['id'], TRUE);
die();
}
/**
* Ja oder Nein
*/
if($action == "jn") {
SendMessageToTelegram((random_int(0, 1) == 1 ? EMOJI_THUMBSUP." JA" : EMOJI_THUMBSDOWN." NEIN"), $response['message']['chat']['id'], TRUE);
die();
}
/**
* Funktion zum generieren von Zufallszahlen
*/
function randomNumbers(int $min = 1, int $max = 49, int $qty = 6) {
$numbers = range($min, $max);
shuffle($numbers);
$numbers = array_slice($numbers, 0, $qty);
sort($numbers);
return implode(", ", $numbers);
}
/**
* Lottozahlen
* 6 aus 49
*/
if($action == "l") {
SendMessageToTelegram(EMOJI_TICKET." *Lottozahlen*:\n".randomNumbers(1, 49, 6), $response['message']['chat']['id'], TRUE);
die();
}
/**
* Eurojackpot Zahlen
* 5 aus 50, 2 aus 10
*/
if($action == "ej") {
SendMessageToTelegram(EMOJI_TICKET." *Eurojackpot-Zahlen:*\n\n*5 aus 50:*\n".randomNumbers(1, 50, 5)."\n\n*2 aus 10:*\n".randomNumbers(1, 10, 2), $response['message']['chat']['id'], TRUE);
die();
}
?>