|
@@ -1,10 +1,13 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-define('BOT_TOKEN', '');
|
|
|
|
|
|
+define('BOT_TOKEN', '<token>');
|
|
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
|
|
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
|
|
|
|
|
|
-$mysql_user = '';
|
|
|
|
-$mysql_pass = '';
|
|
|
|
|
|
+$redis = new Redis();
|
|
|
|
+$redis->connect('127.0.0.1', 6379);
|
|
|
|
+
|
|
|
|
+$mysql_user = 'mysql_user';
|
|
|
|
+$mysql_pass = 'mysql_password';
|
|
|
|
|
|
$db = new PDO('mysql:host=127.0.0.1;dbname=certalertbot;charset=utf8mb4', $mysql_user, $mysql_pass);
|
|
$db = new PDO('mysql:host=127.0.0.1;dbname=certalertbot;charset=utf8mb4', $mysql_user, $mysql_pass);
|
|
|
|
|
|
@@ -24,7 +27,7 @@ To delete a rule.
|
|
<pre>/add <in/start/end> <string>
|
|
<pre>/add <in/start/end> <string>
|
|
</pre>
|
|
</pre>
|
|
To add a rule.
|
|
To add a rule.
|
|
-<i>in</i> mtaches the given substring in any postition, <i>start</i> at the beginning and <i>end</i> at the end
|
|
|
|
|
|
+<i>in</i> matches the given substring in any postition, <i>start</i> at the beginning and <i>end</i> at the end.
|
|
|
|
|
|
For special characters use the IDNA encoding.
|
|
For special characters use the IDNA encoding.
|
|
";
|
|
";
|
|
@@ -75,6 +78,10 @@ switch($command) {
|
|
$exp = explode(" ", $update['message']['text']);
|
|
$exp = explode(" ", $update['message']['text']);
|
|
$type = $exp[1];
|
|
$type = $exp[1];
|
|
$value = $exp[2];
|
|
$value = $exp[2];
|
|
|
|
+ if (strlen($value) < 5) {
|
|
|
|
+ $reply = "The filter must be at least 5 chars.";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
switch($type) {
|
|
switch($type) {
|
|
case 'in':
|
|
case 'in':
|
|
$type = 0;
|
|
$type = 0;
|
|
@@ -92,6 +99,11 @@ switch($command) {
|
|
if ($type > -1) {
|
|
if ($type > -1) {
|
|
$stmt = $db->prepare("INSERT INTO rules (userid, chatid, type, value, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP())");
|
|
$stmt = $db->prepare("INSERT INTO rules (userid, chatid, type, value, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP())");
|
|
$stmt->execute(array($fromid, $chatid, $type, $value));
|
|
$stmt->execute(array($fromid, $chatid, $type, $value));
|
|
|
|
+ $id = $db->lastInsertId();
|
|
|
|
+ $toadd["id"] = $id;
|
|
|
|
+ $toadd["value"] = array("t" => $type, "v" => $value, "c" => $chatid);
|
|
|
|
+ $toadd = json_encode($toadd, JSON_NUMERIC_CHECK);
|
|
|
|
+ $redis->rPush('toadd', $toadd);
|
|
$reply = "Rule added, check with /list";
|
|
$reply = "Rule added, check with /list";
|
|
} else {
|
|
} else {
|
|
$reply = "Invalid rule type.";
|
|
$reply = "Invalid rule type.";
|
|
@@ -103,6 +115,7 @@ switch($command) {
|
|
$id = $exp[1];
|
|
$id = $exp[1];
|
|
$stmt = $db->prepare("DELETE FROM rules WHERE id = ? AND userid = ?");
|
|
$stmt = $db->prepare("DELETE FROM rules WHERE id = ? AND userid = ?");
|
|
$stmt->execute(array($id, $fromid));
|
|
$stmt->execute(array($id, $fromid));
|
|
|
|
+ $redis->rPush('todel', $id);
|
|
$reply = "Rule ".$id." deleted";
|
|
$reply = "Rule ".$id." deleted";
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|