Double bot interface, silent flag
This commit is contained in:
parent
d889e59a31
commit
d0d6964400
|
@ -8,12 +8,16 @@
|
||||||
const API_CHANNEL_ID = '@';
|
const API_CHANNEL_ID = '@';
|
||||||
/* Users whose messages are forwarded to mailing list and channel */
|
/* Users whose messages are forwarded to mailing list and channel */
|
||||||
const BOT_ALLOWED_USERS = array ();
|
const BOT_ALLOWED_USERS = array ();
|
||||||
|
/* Users who can use the new bot interface */
|
||||||
|
const BOT_BETA_TESTERS = array ();
|
||||||
/* Address to forward to */
|
/* Address to forward to */
|
||||||
const MAIL_TO_ADDR = 'example@example.com';
|
const MAIL_TO_ADDR = 'example@example.com';
|
||||||
/* Bot email identity */
|
/* Bot email identity */
|
||||||
const MAIL_FROM_ADDR = 'example@example.com';
|
const MAIL_FROM_ADDR = 'example@example.com';
|
||||||
/* Debug messages on log file */
|
/* Debug messages on log file */
|
||||||
const DEBUG = true;
|
const DEBUG = true;
|
||||||
|
/* Be silent when forwarding/writing messages to channel */
|
||||||
|
const FORWARD_SILENT = true;
|
||||||
/* Log file name */
|
/* Log file name */
|
||||||
const LOGFILE = 'botlog.log';
|
const LOGFILE = 'botlog.log';
|
||||||
/* MySQL informations */
|
/* MySQL informations */
|
||||||
|
|
23
main.php
23
main.php
|
@ -61,7 +61,7 @@ if (isset ($row->callback_query)) {
|
||||||
$chatID = $row->callback_query->message->chat->id;
|
$chatID = $row->callback_query->message->chat->id;
|
||||||
|
|
||||||
// Check if it was thrown by admitted users
|
// Check if it was thrown by admitted users
|
||||||
in_array($row->callback_query->message->chat->username, BOT_ALLOWED_USERS) or not_authorized($chatID);
|
in_array($row->callback_query->message->chat->username, BOT_BETA_TESTERS) or not_authorized($chatID);
|
||||||
|
|
||||||
// Answer to the callback query (remove the loading sign)
|
// Answer to the callback query (remove the loading sign)
|
||||||
if (DEBUG) info("Callback Query, answering");
|
if (DEBUG) info("Callback Query, answering");
|
||||||
|
@ -168,7 +168,7 @@ if (isset ($row->callback_query)) {
|
||||||
$msg = $mc->get($chatID.MC_FORWARD_MSG)
|
$msg = $mc->get($chatID.MC_FORWARD_MSG)
|
||||||
or error("Can't forward message\n");
|
or error("Can't forward message\n");
|
||||||
|
|
||||||
forwardMessage(API_CHANNEL_ID, $msg->message->chat->id, $msg->message->message_id, true);
|
forwardMessage(API_CHANNEL_ID, $msg->message->chat->id, $msg->message->message_id, FORWARD_SILENT);
|
||||||
|
|
||||||
// Remove kbd
|
// Remove kbd
|
||||||
$text = "Invio effettuato correttamente";
|
$text = "Invio effettuato correttamente";
|
||||||
|
@ -256,10 +256,7 @@ if (isset ($row->callback_query)) {
|
||||||
}
|
}
|
||||||
elseif ($callback_data == MSG_ABORT) {
|
elseif ($callback_data == MSG_ABORT) {
|
||||||
$text = "Invio annullato correttamente";
|
$text = "Invio annullato correttamente";
|
||||||
$url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
|
editMessageText($chatID, $inlineID, $text);
|
||||||
"&message_id=".$inlineID .
|
|
||||||
"&text=".urlencode($text);
|
|
||||||
file_get_contents($url);
|
|
||||||
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -330,10 +327,7 @@ if (isset ($row->callback_query)) {
|
||||||
$mc->replace($chatID.MC_STATUS, STATE_IDLE);
|
$mc->replace($chatID.MC_STATUS, STATE_IDLE);
|
||||||
if ($callback_data == MSG_ABORT) {
|
if ($callback_data == MSG_ABORT) {
|
||||||
$text = "Invio annullato correttamente";
|
$text = "Invio annullato correttamente";
|
||||||
$url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
|
editMessageText($chatID, $inlineID, $text);
|
||||||
"&message_id=".$inlineID .
|
|
||||||
"&text=".urlencode($text);
|
|
||||||
file_get_contents($url);
|
|
||||||
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -400,7 +394,11 @@ elseif (isset($row->message)) {
|
||||||
// Load variables
|
// Load variables
|
||||||
$chatID = $row->message->chat->id;
|
$chatID = $row->message->chat->id;
|
||||||
// Check if it was thrown by admitted users
|
// Check if it was thrown by admitted users
|
||||||
in_array($row->message->from->username, BOT_ALLOWED_USERS) or not_authorized($chatID);
|
if (in_array($row->message->from->username, BOT_ALLOWED_USERS)) {
|
||||||
|
info( ' Telegram: forwarding to channel... ');
|
||||||
|
forwardMessage(API_CHANNEL_ID, $row->message->chat->id, $row->message->message_id, FORWARD_SILENT);
|
||||||
|
}
|
||||||
|
else if (in_array($row->message->from->username, BOT_BETA_TESTERS)) {
|
||||||
|
|
||||||
// Finally, check actual state and do things
|
// Finally, check actual state and do things
|
||||||
$status = $mc->get($chatID.MC_STATUS);
|
$status = $mc->get($chatID.MC_STATUS);
|
||||||
|
@ -519,6 +517,9 @@ elseif (isset($row->message)) {
|
||||||
wrong_action($chatID);
|
wrong_action($chatID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
not_authorized($chatID);
|
||||||
}
|
}
|
||||||
// a not supported message (i.e. from a channel)
|
// a not supported message (i.e. from a channel)
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -27,7 +27,7 @@ while ($row = $query->fetch_assoc()) {
|
||||||
"&parse_mode=".urlencode("Markdown");
|
"&parse_mode=".urlencode("Markdown");
|
||||||
file_get_contents($bot_query);
|
file_get_contents($bot_query);
|
||||||
* */
|
* */
|
||||||
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID']) or
|
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID'], FORWARD_SILENT) or
|
||||||
error("Scheduler couldn't forward the message. I'll try next hour");
|
error("Scheduler couldn't forward the message. I'll try next hour");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue