Major revision 2

This commit is contained in:
Mattia Mascarello
2023-02-07 01:27:52 +01:00
parent 6a005fd277
commit 88ce5972b4
919 changed files with 16257 additions and 829872 deletions

97
handlers/Card.php Normal file
View File

@ -0,0 +1,97 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Types\User;
use \TelegramBot\Api\Client;
use \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
class Card extends Command
{
private Database $database;
private ?User $user;
public static function exposedCommands(): array
{
return [];
}
public function __construct(Message $message, Client $bot, Database $database, ?User $user = null)
{
parent::__construct($message, $bot);
$this->database = $database;
$this->user = $user;
}
public function execute(): void
{
if (!$this->replyUser) $this->replyUser = $this->message->getFrom();
$m = $this->message->getReplyToMessage();
if (!$m) {
$this->sendCard($this->message->getFrom(), $this->message->getChat()->getId(), $this->message->getMessageId());
} else {
$this->sendCard($m->getFrom(), $m->getChat()->getId(), $m->getMessageId());
}
}
public function viewPVC(DatabaseUser $du)
{
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->user->getId(),
$du->getLastPrivateMessage()
);
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Ok", 'callback_data' => 'endSet#save']
]
]);
$m = $this->sendCard($this->user, $this->user->getId(), null, $keyboard);
$du->setLastPrivateMessage($m->getMessageId());
$du->setPrivateChatStatus(PrivateChat::STATUS_VIEWING_CARD);
$du->save(false);
}
public function sendCard(User $u, int $chatId, ?int $replyTo = null, $keyboard = null)
{
$du = DatabaseUser::getByChat($this->database, $u);
if ($du->getPrivateChatStatus() != PrivateChat::STATUS_ENDED && $du->getPrivateChatStatus() != PrivateChat::STATUS_VIEWING_CARD) {
$message = $this->bot->sendMessage($chatId, "L'utente non ha ancora impostato i suoi dati o li sta modificando.", "HTML", false, $replyTo, $keyboard);
$du->setPrivateChatStatus(PrivateChat::STATUS_ENDED);
return $message;
}
if ($du->countCompleted() == 0) {
$message = $this->bot->sendMessage($chatId, "Non ci sono dati", "HTML", false, $replyTo, $keyboard);
$du->setPrivateChatStatus(PrivateChat::STATUS_ENDED);
return $message;
}
$ps = $this->bot->getUserProfilePhotos($u->getId())->getPhotos();
$firstPhoto = $ps[0];
$biggest = $firstPhoto[count($firstPhoto) - 1];
$path = $this->bot->getFile($biggest->getFileId())->getFilePath();
$url = "https://api.telegram.org/file/bot" . $GLOBALS["token"] . "/" . $path;
$data = [
"name" => $du->getUName(),
"birth" => $du->getUbirthDate(),
"gender" => $du->getUGender(),
"orientation" => $du->getUOrient(),
"where" => $du->getUPlace(),
"pvt" => $du->getUpvtChoice(),
"rel" => $du->getURelationships(),
"flags" => $du->getFlags(),
"isDev" => $du->getTelegramId() == $GLOBALS["masterId"],
"img" => $url,
"nonce" => bin2hex(random_bytes(16))
];
$height = 480 + floor(count($du->getFlags()) / 5) * 100;
$url = $GLOBALS["imageServer"] . "?access_key=" . $GLOBALS["urltoimagekey"] . "&url=" . $GLOBALS["baseurl"] . "/card.php%3Fdata%3D" . urlencode(json_encode($data)) . "&height=$height&width=600";
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_photo");
try {
$message = $this->bot->sendPhoto(
$chatId,
$url,
"",
$replyTo,
$keyboard,
null,
"HTML"
);
} catch (\TelegramBot\Api\Exception $e) {
$message = $this->bot->sendMessage($chatId, "Non è stato possibile generare l'immagine", "HTML", false, $replyTo, $keyboard);
}
return $message;
}
}

33
handlers/Command.php Normal file
View File

@ -0,0 +1,33 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
class Command
{
protected $message; // Message
protected $bot; // Client
public function __construct(Message $message, Client $bot)
{
$this->message = $message;
$this->bot = $bot;
}
protected function multiExplode(string $string, array $delimiters, int $max = -1): array
{
$l = [];
$temp = "";
$found = 0;
foreach (str_split($string) as $char) {
if (in_array($char, $delimiters)) {
if ($max != -1 && $found == $max) break;
$l[] = $temp;
$temp = "";
$found++;
}
}
return $l;
}
public function execute(): void{
}
}

42
handlers/Eva.php Normal file
View File

@ -0,0 +1,42 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
class Eva extends Command
{
public static function exposedCommands(): array
{
return [];
}
public function __construct(Message $message, Client $bot)
{
parent::__construct($message, $bot);
}
public function execute(): void
{
$remaining = PictureAPIRateLimitHandler::countAdd();
if ($remaining->getFinished() == CountAddResult::FINISHED_TODAY) {
$message = $this->bot->sendMessage($this->message->getChat()->getId(), "È stato raggiunto il numero massimo di immagini giornaliero (" . $remaining->getDailyLimit() . ")", "HTML", false);
} elseif ($remaining->getFinished() == CountAddResult::FINISHED_UNTIL_RENEW) {
$message = $this->bot->sendMessage($this->message->getChat()->getId(), "È stato raggiunto il numero massimo di immagini ( stop fino a " . date("d/m/Y H:i:s", $remaining->getReset()) . ")", "HTML", false);
} else {
$m = $this->message->getReplyToMessage();
if (!$m) {
$this->bot->sendMessage($this->message->getChat()->getId(), "Cita un messaggio di testo", null, false, $this->message->getMessageId());
} else {
$url = "https://api.apiflash.com/v1/urltoimage?access_key=" . $GLOBALS["urltoimagekey"] . "&url=" . $GLOBALS["baseurl"] . "/eva.php%3Fdata%3D" . urlencode(json_encode(explode("\n", $m->getText()))) . "&height=478&width=600";
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_photo");
$this->bot->sendPhoto(
$this->message->getChat()->getId(),
$url,
$remaining->getRemainingToday() . " immagini rimanenti oggi",
$this->message->getMessageId(),
null,
null,
"HTML"
);
}
}
}
}

87
handlers/Explain.php Normal file
View File

@ -0,0 +1,87 @@
<?php
require_once "common.php";
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Types\User;
use \TelegramBot\Api\Client;
use \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
class Explain extends Command
{
private Database $database;
private ?User $user;
public static function exposedCommands(): array
{
return [];
}
public function __construct(Message $message, Client $bot, Database $database, ?User $user = null)
{
parent::__construct($message, $bot);
$this->database = $database;
$this->user = $user;
}
public static function toText(DatabaseUser $du): string
{
if ($du->getPrivateChatStatus() != PrivateChat::STATUS_ENDED && $du->getPrivateChatStatus() != PrivateChat::STATUS_VIEWING_CARD) {
return "L'utente non ha ancora impostato i suoi dati o li sta modificando.";
}
$text = "Provo a spiegare:\n";
$name = $du->getUName() ?: $du->getName();
$g = strtoupper($du->getUGender());
$o = strtoupper($du->getUOrient());
if (contains("TRANS", $g) || contains("MTF", $g) || contains("FTM", $g)) $text .= "\n$name è transgender, questo significa che la sua identità di genere (autopercezione del genere) diverge dal suo sesso biologico.";
if (contains("FTM", $g)) $text .= "\nNello specifico il genere percepito da $name è Maschile.";
if (contains("MTF", $g)) $text .= "\nNello specifico il genere percepito da $name è Femmnile.";
if (contains("UOMO", $g)) $text .= "\n$name si percepisce come uomo.";
if (contains("DONNA", $g)) $text .= "\n$name si percepisce come donna.";
if (contains("NON-BINARY", $g)) $text .= "\n$name si percepisce come non-binary (non-binario).\nLa sua identità di genere (genere autopercepito) è al di fuori del cosiddetto binarismo di genere, ovvero non strettamente e/o completamente maschile o femminile.";
if (contains("DEMIBOY", $g)) $text .= "\n$name si percepisce come parzialmente come uomo (demiboy).";
if (contains("DEMIGIRL", $g)) $text .= "\n$name si percepisce come parzialmente come donna (demigirl).";
if (contains("GENDERQUEER", $g)) $text .= "\n$name si percepisce come genderqueer, ovvero in una relazione non-normata rispetto al proprio genere.";
if (contains("ETERO", $o)) $text .= "\n$name è eterosessuale, ovvero sperimenta attrazione verso persone del genere opposto.";
if (contains("GAY", $o)) $text .= "\n$name è gay, ovvero sperimenta attrazione verso persone dello stesso genere.";
if (contains("LESBICA", $o)) $text .= "\n$name è lesbica, ovvero sperimenta attrazione verso persone dello stesso genere.";
if (contains("ASESSUALE", $o)) $text .= "\n$name è asessuale, ovvero non sperimenta attrazione.";
if (contains("PANSESSUALE", $o)) $text .= "\n$name è pansessuale, ovvero sperimenta attrazione verso persone di tutti i generi.";
if (contains("BISESSUALE", $o)) $text .= "\n$name è bisessuale, ovvero sperimenta attrazione verso persone di tutti i generi.";
if (contains("DEMISESSUALE", $o)) $text .= "\n$name è demisessuale, ovvero sperimenta attrazione solo verso persone con cui ha un forte legame emotivo.";
if (contains("QUESTIONING", $o)) $text .= "\n$name è questioning, ovvero sta comprendendo e/o esplorando la propria sessualità.";
if ($text == "Provo a spiegare:\n") $text = "Non ho dati sufficienti o conformi al mio database per spiegare";
return $text;
}
public function execute(): void
{
if (!$this->replyUser) $this->replyUser = $this->message->getFrom();
$m = $this->message->getReplyToMessage();
if (!$m) {
$du = DatabaseUser::getByChat($this->database, $this->message->getFrom());
$this->bot->sendMessage($this->message->getChat()->getId(), self::toText($du), "HTML", false, $this->message->getMessageId());
} else {
$du = DatabaseUser::getByChat($this->database, $m->getFrom());
$this->bot->sendMessage($m->getChat()->getId(), self::toText($du), "HTML", false, $m->getMessageId());
}
}
public function pvtLookup(DatabaseUser $du)
{
if ($du->getLastPrivateMessage() != 0) {
try {
$this->bot->deleteMessage(
$this->user->getId(),
$du->getLastPrivateMessage()
);
} catch (\TelegramBot\Api\Exception $e) {
}
}
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Ok", 'callback_data' => 'endSet#save']
]
]);
$message = $this->bot->sendMessage($this->user->getId(), self::toText($du), "HTML", false, null, $keyboard);
$du->setLastPrivateMessage($message->getMessageId());
$du->setPrivateChatStatus(PrivateChat::STATUS_VIEWING_CARD);
$du->save(false);
}
}

65
handlers/Flip.php Normal file
View File

@ -0,0 +1,65 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
class Flip extends Command
{
const VERTICAL = 0;
const HORIZONTAL = 1;
const BOTH = 2;
public static function exposedCommands(): array
{
return [];
}
private int $mode;
public function __construct(Message $message, Client $bot, int $mode)
{
parent::__construct($message, $bot);
$this->mode = $mode;
}
public function execute(): void
{
$m = $this->message->getReplyToMessage();
if (!$m) {
$this->bot->sendMessage($this->message->getChat()->getId(), "Cita una foto (nessun messaggio citato)", null, false, $this->message->getMessageId());
} else {
$p = $m->getPhoto();
if (!$p) {
$this->bot->sendMessage($this->message->getChat()->getId(), "Cita una foto (non hai citato una foto)", null, false, $this->message->getMessageId());
} else {
$biggest = $p[count($p) - 1];
$path = $this->bot->getFile($biggest->getFileId())->getFilePath();
$url = "https://api.telegram.org/file/bot" . $GLOBALS["token"] . "/" . $path;
if (!file_exists('tempImageProcessing')) {
mkdir('tempImageProcessing');
}
$io = bin2hex(random_bytes(10));
$filename = "tempImageProcessing/" . $io . ".jpg";
$ch = curl_init($url);
$fp = fopen($filename, 'wb+');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$im = imagecreatefromjpeg($filename);
if ($this->mode == self::VERTICAL || $this->mode == self::BOTH) imageflip($im, IMG_FLIP_VERTICAL);
if ($this->mode == self::HORIZONTAL || $this->mode == self::BOTH) imageflip($im, IMG_FLIP_HORIZONTAL);
if ($this->mode == self::VERTICAL) $text = "Rovesciato in <b>Verticale</b>";
if ($this->mode == self::HORIZONTAL) $text = "Rovesciato in <b>Orizzontale</b>";
if ($this->mode == self::BOTH) $text = "Rovesciato in <b>Orizzontale e Verticale</b>";
imagejpeg($im, $filename);
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_photo");
$this->bot->sendPhoto(
$this->message->getChat()->getId(),
$GLOBALS["baseurl"] . "/tempImageProcessing/getter.php?photo=" . $io,
$text,
$this->message->getMessageId(),
null,
null,
"HTML"
);
}
}
}
}

56
handlers/GroupWatcher.php Normal file
View File

@ -0,0 +1,56 @@
<?php
use TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
use \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
class GroupWatcher
{
public static function watch(Database $database, Message $message, Client $bot): void
{
$isNew = false;
try {
$du = DatabaseUser::getByChat($database, $message->getFrom());
if ($du->getPrivateChatStatus() == PrivateChat::STATUS_STRAY_USER) {
self::createMessageStray($database, $message, $bot);
$du->setPrivateChatStatus(PrivateChat::STATUS_ASK_DM);
}
$du->save(false);
} catch (NotFoundException $e) {
$isNew = true;
self::createMessageNormal($database, $message, $bot);
$du = DatabaseUser::create($database, $message->getFrom());
$du->setPrivateChatStatus(PrivateChat::STATUS_ASK_DM);
$du->poke($message->getFrom());
}
$r = Group::poke($database, $message, $du);
$shouldSendSeen = $r[1];
$shouldSendNewGroup = $r[0];
if ($shouldSendSeen && !$isNew) $bot->sendMessage($message->getChat()->getId(), "Benvenutə, ti ho già visto in precedenza.\n" . Lookup::toText($du), "HTML", false, $message->getMessageId());
if ($shouldSendNewGroup) $bot->sendMessage($message->getChat()->getId(), "Sono in un nuovo gruppo! yay. Ricordatevi di darmi accesso ai messaggi per accogliere i nuovi arrivati.", "HTML", false, $message->getMessageId());
if ($shouldSendNewGroup) $bot->sendMessage($GLOBALS["logId"], "Sono in un nuovo gruppo! " . $message->getChat()->getTitle() . "(@" . $message->getChat()->getUsername() . ")", "HTML", false);
}
public static function getCommonKeyboard(): InlineKeyboardMarkup
{
return $keyboard = new InlineKeyboardMarkup([
[
['text' => "✏️ Compila", 'url' => 'https://t.me/' . $GLOBALS["username"]],
['text' => "❓ Cosa fa questo bot?", 'callback_data' => 'whatIsThis'],
['text' => "🚫 Escludimi dal bot", 'url' => 'https://t.me/' . $GLOBALS["username"]]
]
]);
}
public static function createMessageNormal(Database $database, Message $message, Client $bot): void
{
$keyboard = self::getCommonKeyboard();
$bot->sendMessage($message->getChat()->getId(), "Benvenutə, questo bot gestisce un sistema di profili su questo ed altri gruppi!", null, false, $message->getMessageId(), $keyboard);
}
public static function createMessageStray(Database $database, Message $message, Client $bot): void
{
$keyboard = self::getCommonKeyboard();
$bot->sendMessage($message->getChat()->getId(), "Benvenutə!\n Mi avevi scritto prima di entrare in un gruppo in cui c'ero e non potevo creare il profilo, ma ora posso.\n Questo bot gestisce un sistema di profili su questo ed altri gruppi!", null, false, $message->getMessageId(), $keyboard);
}
}

31
handlers/Inspire.php Normal file
View File

@ -0,0 +1,31 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
class Inspire extends Command
{
public static function exposedCommands(): array
{
return [];
}
public function __construct(Message $message, Client $bot)
{
parent::__construct($message, $bot);
}
public function execute(): void
{
$url = file_get_contents("https://inspirobot.me/api?generate=true");
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_photo");
$this->bot->sendPhoto(
$this->message->getChat()->getId(),
$url,
null,
$this->message->getMessageId(),
null,
null,
"HTML"
);
}
}

73
handlers/Lookup.php Normal file
View File

@ -0,0 +1,73 @@
<?php
require_once "common.php";
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Types\User;
use \TelegramBot\Api\Client;
use \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
class Lookup extends Command
{
private Database $database;
private ?User $user;
public static function exposedCommands(): array
{
return [];
}
public function __construct(Message $message, Client $bot, Database $database, ?User $user = null)
{
parent::__construct($message, $bot);
$this->database = $database;
$this->user = $user;
}
public static function toText(DatabaseUser $du): string
{
if ($du->getPrivateChatStatus() != PrivateChat::STATUS_ENDED && $du->getPrivateChatStatus() != PrivateChat::STATUS_VIEWING_CARD) {
return "L'utente non ha ancora impostato i suoi dati o li sta modificando.";
}
$text = "";
if ($du->getUName()) $text .= "\n\n<b>Nome</b>: \n" . $du->getUName();
if ($du->getUbirthDate()) $text .= "\n\n<b>Data di Nascita</b>: \n" . itdate($du->getUbirthDate()) . " (" . DatabaseUser::calcAge($du->getUbirthDate()) . " anni)";
if ($du->getUGender()) $text .= "\n\n<b>Genere</b>: \n" . $du->getUGender();
if ($du->getUOrient()) $text .= "\n\n<b>Orientamento</b>: \n" . $du->getUOrient();
if ($du->getUPlace()) $text .= "\n\n<b>Provenienza</b>: \n" . $du->getUPlace();
if ($du->getURelationships()) $text .= "\n\n<b>Relazioni</b>: \n" . $du->getURelationships();
if ($du->getUBio()) $text .= "\n\n<b>Bio</b>: \n" . $du->getUBio();
if (strlen($text) == 0) $text = "Non ci sono dati";
return $text;
}
public function execute(): void
{
if (!$this->replyUser) $this->replyUser = $this->message->getFrom();
$m = $this->message->getReplyToMessage();
if (!$m) {
$du = DatabaseUser::getByChat($this->database, $this->message->getFrom());
$this->bot->sendMessage($this->message->getChat()->getId(), self::toText($du), "HTML", false, $this->message->getMessageId());
} else {
$du = DatabaseUser::getByChat($this->database, $m->getFrom());
$this->bot->sendMessage($m->getChat()->getId(), self::toText($du), "HTML", false, $m->getMessageId());
}
}
public function pvtLookup(DatabaseUser $du)
{
if ($du->getLastPrivateMessage() != 0) {
try {
$this->bot->deleteMessage(
$this->user->getId(),
$du->getLastPrivateMessage()
);
} catch (\TelegramBot\Api\Exception $e) {
}
}
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Ok", 'callback_data' => 'endSet#save']
]
]);
$message = $this->bot->sendMessage($this->user->getId(), self::toText($du), "HTML", false, null, $keyboard);
$du->setLastPrivateMessage($message->getMessageId());
$du->setPrivateChatStatus(PrivateChat::STATUS_VIEWING_CARD);
$du->save(false);
}
}

788
handlers/PrivateChat.php Normal file
View File

@ -0,0 +1,788 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
use \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
use \TelegramBot\Api\Types\User;
//Change Users Class and fb to store all user data in one table
class PrivateChat extends Command
{
const STATUS_ASK_DM = "askDm";
const STATUS_CONSENT = "consent";
const STATUS_ASK_NAME = "askName";
const STATUS_ASK_BIRTH = "askBirth";
const STATUS_ASK_GENDER = "askGender";
const STATUS_ASK_ORIENT = "askOrient";
const STATUS_ASK_WHERE = "askWhere";
const STATUS_ASK_PVT = "askPVT";
const STATUS_ASK_REL = "askrel";
const STATUS_ASK_BIO = "askBio";
const STATUS_EDITING = "edit";
const STATUS_STRAY_USER = "stray";
const STATUS_EXCLUDED = "exclude";
const STATUS_NOT_CONSENT = "notConsent";
const STATUS_ENDED = "ended";
const STATUS_VIEWING_CARD = "card";
const STATUS_MESSAGE_SEND = "msgsend";
private Database $database;
public static function exposedCommands(): array
{
return [];
}
private ?User $replyUser;
public function __construct(Message $message, Client $bot, Database $database, User $replyUser = null)
{
parent::__construct($message, $bot);
$this->database = $database;
$this->replyUser = $replyUser;
}
public function execute(bool $mustSet = true): void
{
if (!$this->replyUser) $this->replyUser = $this->message->getFrom();
try {
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
switch ($du->getPrivateChatStatus()) {
case self::STATUS_ASK_DM:
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Acconsento", 'callback_data' => 'yesPolicy'],
['text' => "❌ Non Acconsento", 'callback_data' => 'noPolicy']
],
[
['text' => "🚫 Escludimi dal bot", 'callback_data' => "excludeMe"]
]
]);
$message = $this->bot->sendMessage($this->replyUser->getId(), "Per procedere, occorre acconsentire alla <a href=\"https://telegra.ph/Rainbow-Bot----Privacy-policy-08-04\">Privacy Policy</a>", "HTML", false, null, $keyboard);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$du->setOptedOut(false);
$du->setLastPrivateMessage($message->getMessageId());
$du->poke($this->replyUser);
break;
case self::STATUS_STRAY_USER:
throw new NotFoundException(); // trigger stray user message
break;
case self::STATUS_ASK_NAME:
if ($mustSet) $du->setUName(ellipses($this->message->getText()));
$du->save(false);
$this->askName($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_BIRTH:
$text = $this->message->getText();
$text = str_replace("-", "/", $text);
$text = str_replace(".", "/", $text);
$e = explode("/", $text);
$builtDate = strtotime($e[2] . "-" . $e[1] . "-" . $e[0]);
if ($mustSet) {
if (!ctype_digit($e[0])) $invalid = true;
elseif (!ctype_digit($e[1])) $invalid = true;
elseif (!ctype_digit($e[2])) $invalid = true;
else $invalid = !checkdate((int) $e[1], (int) $e[0], (int) $e[2]);
if (!$invalid) $du->setUbirthDate($builtDate);
} else {
$invalid = false;
}
$du->save(false);
$this->askBirthDate($du, $invalid);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_GENDER:
if ($mustSet) $du->setUGender(ellipses($this->message->getText()));
$du->save(false);
$this->askGender($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_ORIENT:
if ($mustSet) $du->setUOrient(ellipses($this->message->getText()));
$du->save(false);
$this->askOrient($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_WHERE:
if ($mustSet) $du->setUPlace(ellipses($this->message->getText()));
$du->save(false);
$this->askWhere($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_PVT:
if ($mustSet) $du->setUpvtChoice(ellipses($this->message->getText()));
$du->save(false);
$this->askPVT($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_REL:
if ($mustSet) $du->setURelationships(ellipses($this->message->getText()));
$du->save(false);
$this->askRel($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ASK_BIO:
if ($mustSet) $du->setUBio(ellipses($this->message->getText(), 500));
$du->save(false);
$this->askBio($du);
try {
if ($mustSet) $this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);
} catch (\TelegramBot\Api\Exception $e) {
}
break;
case self::STATUS_ENDED:
$this->completedMenu();
/*$this->bot->deleteMessage(
$this->replyUser->getId(),
$this->message->getMessageId()
);*/
break;
case self::STATUS_EXCLUDED:
$this->excludeYes();
break;
case self::STATUS_NOT_CONSENT:
$this->noPolicy();
case self::STATUS_MESSAGE_SEND:
$this->sendMessageToGroups($this->message->getText());
break;
}
} catch (NotFoundException $e) {
$message = $this->bot->sendMessage($this->replyUser->getId(), "Per usare questo bot devi avere prima partecipato ad un gruppo a cui appartiene.", "HTML", false);
$du = DatabaseUser::create($this->database, $this->replyUser);
$du->setPrivateChatStatus(self::STATUS_STRAY_USER);
$du->setLastPrivateMessage($message->getMessageId());
$du->poke($this->replyUser);
}
}
public static function isPrivateChatContextChecker($update): bool
{
if ($update instanceof Message) return $update->getChat()->getType() == "private";
else return $update->getMessage()->getChat()->getType() == "private";
}
public static function isPublicChatContextChecker($update): bool
{
return !PrivateChat::isPrivateChatContextChecker($update);
}
public function sendMessageToGroups(string $data): void
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$list = Group::listAll($this->database);
$text = "Inviando a...\n\n";
foreach ($list as $group) {
$text .= "➡️ " . $group->getName();
if ($group->getUsername()) $text .= " (" . $group->getUsername() . ")";
$text .= "\n";
try {
$this->bot->sendMessage($group->getTelegramId(), $data, "HTML", false, null);
$text .= ": ✅ OK\n";
} catch (Exception $e) {
$text .= ": ❌ Errore\n";
}
}
$text .= "\n\n ... fatto";
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅Ok", 'callback_data' => 'endSet#save']
]
]);
$message = $this->bot->sendMessage($this->replyUser->getId(), $text, "HTML", false, null, $keyboard);
$du->setPrivateChatStatus(self::STATUS_ENDED);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function writeMessage(): void
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$keyboard = new InlineKeyboardMarkup([
[
['text' => "❌ Annulla", 'callback_data' => 'endSet#save']
]
]);
$message = $this->bot->sendMessage($this->replyUser->getId(), "Scrivi un messaggio in formato HTML da inviare a <b>tutti i gruppi</b>", "HTML", false, null, $keyboard);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$du->setPrivateChatStatus(self::STATUS_MESSAGE_SEND);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function exclude(): void
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Escludimi", 'callback_data' => 'yesExclude'],
['text' => "❌ Annulla", 'callback_data' => 'noExclude']
]
]);
$message = $this->bot->sendMessage($this->replyUser->getId(), "Con questa scelta il bot eliminetà i tuoi dati, non ti disturberà più e non salverà tuoi dati finchè tu non lo richiederai\n<b>Non sei sicurə?</b> Puoi sempre cambiare idea più tardi!", "HTML", false, null, $keyboard);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
private function getStateVal(DatabaseUser $u, string $c): ?string
{
if ($c == PrivateChat::STATUS_ASK_NAME) return $u->getUName();
if ($c == PrivateChat::STATUS_ASK_BIRTH) return $u->getUbirthDate();
if ($c == PrivateChat::STATUS_ASK_GENDER) return $u->getUGender();
if ($c == PrivateChat::STATUS_ASK_ORIENT) return $u->getUOrient();
if ($c == PrivateChat::STATUS_ASK_WHERE) return $u->getUPlace();
if ($c == PrivateChat::STATUS_ASK_PVT) return $u->getUpvtChoice();
if ($c == PrivateChat::STATUS_ASK_REL) return $u->getURelationships();
if ($c == PrivateChat::STATUS_ASK_BIO) return $u->getUBio();
return null;
}
public static array $order = [
self::STATUS_ASK_NAME,
self::STATUS_ASK_BIRTH,
self::STATUS_ASK_GENDER,
self::STATUS_ASK_ORIENT,
self::STATUS_ASK_WHERE,
self::STATUS_ASK_PVT,
self::STATUS_ASK_REL,
self::STATUS_ASK_BIO
];
private function getPrevState(string $state): ?string
{
$index = array_search($state, self::$order);
if ($index === false) throw new NotFoundException();
if ($index === 0) return null;
return self::$order[$index - 1];
}
private static function getNextState(string $state): ?string
{
$index = array_search($state, self::$order);
if ($index === false) throw new NotFoundException();
if ($index === count(self::$order) - 1) return null;
return self::$order[$index + 1];
}
private static function getRemaining(string $state): int
{
$index = array_search($state, self::$order);
return count(self::$order) - $index - 1;
}
private function getKeyboard(DatabaseUser $du, string $state, array $nextRows)
{
$list = [];
$prev = $this->getPrevState($state);
$next = $this->getNextState($state);
if ($prev) {
if ($this->getStateVal($du, $prev)) {
$list[] = [['text' => "⏮️✏️ Indietro", 'callback_data' => 'go#' . $prev]];
} else {
$list[] = [['text' => "⏮️🆕 Indietro", 'callback_data' => 'go#' . $prev]];
}
}
if ($this->getStateVal($du, $state)) $list[] = [['text' => "🔄 Reimposta", 'callback_data' => 'go#' . $state . "#reset"]];
if ($next) {
if ($this->getStateVal($du, $next)) {
if (!$this->getStateVal($du, $state)) $list[] = [['text' => "⏭✏️ Avanti (salta questa)", 'callback_data' => 'go#' . $next]];
else $list[] = [['text' => "⏭✏️ Avanti", 'callback_data' => 'go#' . $next]];
} else {
if (!$this->getStateVal($du, $state)) $list[] = [['text' => "⏭🆕 Avanti (salta questa)", 'callback_data' => 'go#' . $next]];
else $list[] = [['text' => "⏭🆕 Avanti", 'callback_data' => 'go#' . $next]];
}
if ($du->countCompleted() == count(self::$order)) $list[] = [['text' => "✅ Fine", 'callback_data' => 'endSet']];
else $list[] = [['text' => "✅ Fine (" . $du->countCompleted() . "/" . count(self::$order) . " domande completate)", 'callback_data' => 'endSet']];
} else {
$list[] = [['text' => "✅ Fine", 'callback_data' => 'endSet']];
}
$list = array_merge($list, $nextRows); // concat arrays
return $list;
}
public function excludeYes()
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$du->setPrivateChatStatus(self::STATUS_EXCLUDED);
$du->setUName(null);
$du->setUbirthDate(null);
$du->setUGender(null);
$du->setUOrient(null);
$du->setUPlace(null);
$du->setUpvtChoice(null);
$du->setURelationships(null);
$du->setUBio(null);
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Riabilitami", 'callback_data' => 'noExclude']
]
]);
$message = $this->bot->sendMessage($this->replyUser->getId(), "La tua scelta è stata confermata. Io rimango qui se cambi idea.", "HTML", false, null, $keyboard);
$du->setLastPrivateMessage($message->getMessageId());
$du->setOptedOut(true);
$du->save(false);
}
public function completedMenu(): void
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$keys = [
[
['text' => "✏️" . ($du->getUName() ? "" : "🆕") . "Modifica Nome", 'callback_data' => 'go#' . self::STATUS_ASK_NAME],
['text' => "✏️" . ($du->getUbirthDate() ? "" : "🆕") . "Modifica Data di Nascita", 'callback_data' => 'go#' . self::STATUS_ASK_BIRTH]
],
[
['text' => "✏️" . ($du->getUGender() ? "" : "🆕") . "Modifica Genere", 'callback_data' => 'go#' . self::STATUS_ASK_GENDER],
['text' => "✏️" . ($du->getUOrient() ? "" : "🆕") . "Modifica Orientamento", 'callback_data' => 'go#' . self::STATUS_ASK_ORIENT]
],
[
['text' => "✏️" . ($du->getUPlace() ? "" : "🆕") . "Modifica Provenienza", 'callback_data' => 'go#' . self::STATUS_ASK_WHERE],
['text' => "✏️" . ($du->getUpvtChoice() ? "" : "🆕") . "Modifica Messaggi privati", 'callback_data' => 'go#' . self::STATUS_ASK_PVT]
],
[
['text' => "✏️" . ($du->getURelationships() ? "" : "🆕") . "Modifica Relazioni", 'callback_data' => 'go#' . self::STATUS_ASK_REL],
['text' => "✏️" . ($du->getUBio() ? "" : "🆕") . "Modifica Bio", 'callback_data' => 'go#' . self::STATUS_ASK_BIO]
],
[
['text' => "💳Visualizza Card", 'callback_data' => 'viewCard']
],
[
['text' => "📄Visualizza Info", 'callback_data' => 'viewInfo']
],
[
['text' => "🔍Visualizza Spiegazione", 'callback_data' => 'viewExp']
],
[
['text' => "🚫 Rimuovi consenso", 'callback_data' => "excludeMe"]
]
];
if ($this->replyUser->getId() == $GLOBALS["masterId"]) {
$keys[] = [
['text' => "✏️ Scrivi messaggio", 'callback_data' => "writeMessage"]
];
}
$keyboard = new InlineKeyboardMarkup($keys);
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Menu</b>",
"HTML",
false,
null,
$keyboard
);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function end($ask = false)
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
if (!$ask) {
$du->setPrivateChatStatus(self::STATUS_ENDED);
$add = "";
/*$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"Abbiamo Finito!" . $add,
"HTML",
false,
null
);*/
$du->save(false);
$this->completedMenu();
} else {
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅Salva comunque", 'callback_data' => 'endSet#save']
],
[
['text' => "⏭✏Torna alla modifica", 'callback_data' => 'go#' . $du->getPrivateChatStatus()]
],
[
['text' => "Rivedi le domande", 'callback_data' => 'go#' . self::STATUS_ASK_NAME],
]
]);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = $du->listUncompleted();
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Alcune domande non hanno risposta</b>:" . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
}
public function yesPolicy()
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"Grazie! Ora possiamo procedere a costruire il tuo profilo\nTi farò una serie di domande.\nRicordati che <b>puoi sempre saltare domande specifiche</b>\n Le risposte saranno visibili in tutti i gruppi che adottano questo bot.",
"HTML"
);
$du->setLastPrivateMessage($message->getMessageId());
$du->setPolicyAccepted(true);
$du->save(false);
$this->askName($du);
}
public function askName(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_NAME);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_NAME, []));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUName()) $add = "\nRisposta corrente: <i>" . $du->getUName() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Come ti Chiami?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askBio(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_BIO);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_BIO, []));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUBio()) $add = "\nRisposta corrente: <i>" . $du->getUBio() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Scrivi una breve descrizione di te stessə (bio)</b> (massimo <b>500</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askGender(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_GENDER);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_GENDER, [
[
['text' => "Uomo", 'callback_data' => 'setGender#Uomo'],
['text' => "Donna", 'callback_data' => 'setGender#Donna'],
['text' => "Non-Binary", 'callback_data' => 'setGender#Non-Binary']
],
[
['text' => "Donna Transgender (MtF)", 'callback_data' => 'setGender#Donna Transgender (MtF)'],
['text' => "Uomo Transgender (FtM)", 'callback_data' => 'setGender#Uomo Transgender (FtM)']
],
[
['text' => "Non-Binary Transgender", 'callback_data' => 'setGender#Non-Binary Transgender'],
['text' => "Genderqueer", 'callback_data' => 'setGender#Genderqueer']
],
[
['text' => "Demiboy", 'callback_data' => 'setGender#Demiboy'],
['text' => "Demigirl", 'callback_data' => 'setGender#Demigirl']
],
[
['text' => "👉Imposta Personalizzato", 'callback_data' => 'setGender#custom']
]
]));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUGender()) $add = "\nRisposta corrente: <i>" . $du->getUGender() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Quel'è il tuo genere?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askRel(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_REL);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_REL, [
[
['text' => "Fidanzatə", 'callback_data' => 'setRel#Fidanzatə'],
['text' => "Single", 'callback_data' => 'setRel#Single'],
['text' => "Aiutatemi vi prego", 'callback_data' => 'setRel#Aiutatemi vi prego']
],
[
['text' => "👉Imposta Personalizzato", 'callback_data' => 'setRel#custom']
]
]));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getURelationships()) $add = "\nRisposta corrente: <i>" . $du->getURelationships() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Relazioni?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askPVT(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_PVT);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_PVT, [
[
['text' => "", 'callback_data' => 'setPVT#Sì'],
['text' => "No", 'callback_data' => 'setPVT#No'],
['text' => "Solo se mi chiedono prima", 'callback_data' => 'setPVT#Solo se mi chiedono prima']
],
[
['text' => "👉Imposta Personalizzato", 'callback_data' => 'setPVT#custom']
]
]));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUpvtChoice()) $add = "\nRisposta corrente: <i>" . $du->getUpvtChoice() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Vuoi poter essere contattatə dagli altri utenti?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askWhere(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_WHERE);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_WHERE, [
[
['text' => "Abruzzo", 'callback_data' => 'setWhere#Abruzzo'],
['text' => "Basilicata", 'callback_data' => 'setWhere#Basilicata'],
['text' => "Calabria", 'callback_data' => 'setWhere#Calabria']
],
[
['text' => "Campania", 'callback_data' => 'setWhere#Campania'],
['text' => "Emilia-Romagna", 'callback_data' => 'setWhere#Emilia-Romagna'],
['text' => "Friuli-Venezia Giulia", 'callback_data' => 'setWhere#Friuli-Venezia Giulia']
],
[
['text' => "Lazio", 'callback_data' => 'setWhere#Lazio'],
['text' => "Liguria", 'callback_data' => 'setWhere#Liguria'],
['text' => "Lombardia", 'callback_data' => 'setWhere#Lombardia']
],
[
['text' => "Marche", 'callback_data' => 'setWhere#Marche'],
['text' => "Molise", 'callback_data' => 'setWhere#Molise'],
['text' => "Piemonte", 'callback_data' => 'setWhere#Piemonte']
],
[
['text' => "Puglia", 'callback_data' => 'setWhere#Puglia'],
['text' => "Sardegna", 'callback_data' => 'setWhere#Sardegna'],
['text' => "Sicilia", 'callback_data' => 'setWhere#Sicilia']
],
[
['text' => "Toscana", 'callback_data' => 'setWhere#Toscana'],
['text' => "Trentino-Alto Adige", 'callback_data' => 'setWhere#Trentino-Alto Adige'],
['text' => "Umbria", 'callback_data' => 'setWhere#Umbria']
],
[
['text' => "Valle d'Aosta", 'callback_data' => 'setWhere#Valle d\'Aosta'],
['text' => "Veneto", 'callback_data' => 'setWhere#Veneto']
],
[
['text' => "👉Imposta Personalizzato", 'callback_data' => 'setWhere#custom']
]
]));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUPlace()) $add = "\nRisposta corrente: <i>" . $du->getUPlace() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Da dove vieni?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askOrient(DatabaseUser $du)
{
$du->setPrivateChatStatus(self::STATUS_ASK_ORIENT);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_ORIENT, [
[
['text' => "Etero", 'callback_data' => 'setOrient#Etero'],
['text' => "Gay", 'callback_data' => 'setOrient#Gay'],
['text' => "Bisessuale", 'callback_data' => 'setOrient#Bisessuale']
],
[
['text' => "Lesbica", 'callback_data' => 'setOrient#Lesbica'],
['text' => "Pansessuale", 'callback_data' => 'setOrient#Pansessuale'],
['text' => "Asessuale", 'callback_data' => 'setOrient#Asessuale']
],
[
['text' => "Demisessuale", 'callback_data' => 'setOrient#Demisessuale'],
['text' => "Questioning", 'callback_data' => 'setOrient#Questioning'],
],
[
['text' => "👉Imposta Personalizzato", 'callback_data' => 'setOrient#custom']
]
]));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($du->getUOrient()) $add = "\nRisposta corrente: <i>" . $du->getUOrient() . "</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Quel'è il tuo orientamento?</b> (massimo <b>40</b> caratteri) " . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function askBirthDate(DatabaseUser $du, bool $invalid = false)
{
$du->setPrivateChatStatus(self::STATUS_ASK_BIRTH);
$keyboard = new InlineKeyboardMarkup($this->getKeyboard($du, self::STATUS_ASK_BIRTH, []));
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$add = "";
if ($invalid) $add .= "\n<b>Data invalida</b>";
if ($du->getUbirthDate()) $add .= "\nRisposta corrente: <i>" . date("d/m/Y", $du->getUbirthDate()) . " (" . $du->getAge() . " anni)</i>";
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"Quando Sei Natə?\n<b>Formato data: giorno/mese/anno</b>" . $add,
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
public function noPolicy()
{
$du = DatabaseUser::getByChat($this->database, $this->replyUser);
$du->setPrivateChatStatus(self::STATUS_NOT_CONSENT);
if ($du->getLastPrivateMessage() != 0) $this->bot->deleteMessage(
$this->replyUser->getId(),
$du->getLastPrivateMessage()
);
$keyboard = new InlineKeyboardMarkup([
[
['text' => "✅ Ho cambiato idea", 'callback_data' => 'changedIdea']
]
]);
$message = $this->bot->sendMessage(
$this->replyUser->getId(),
"<b>Nessun Problema</b>, torna se hai cambiato idea. \nTi lascio la mia <a href=\"https://telegra.ph/Rainbow-Bot----Privacy-policy-08-04\">privacy policy</a> da consultare",
"HTML",
false,
null,
$keyboard
);
$du->setLastPrivateMessage($message->getMessageId());
$du->save(false);
}
}

42
handlers/Rave.php Normal file
View File

@ -0,0 +1,42 @@
<?php
use \TelegramBot\Api\Types\Message;
use \TelegramBot\Api\Client;
class Rave extends Command
{
public static function exposedCommands(): array
{
return [];
}
const CLASSIC = "classic";
const GARFIELD = "garfield";
const MEGALOVANIA = "megalovania";
const OTAMATONE = "otamatone";
private string $mode;
public function __construct(Message $message, Client $bot, string $mode)
{
parent::__construct($message, $bot);
$this->mode = $mode;
}
public function execute(): void
{
$m = $this->message->getReplyToMessage();
if (!$m) {
$this->bot->sendMessage($this->message->getChat()->getId(), "Cita un messaggio di testo", null, false, $this->message->getMessageId());
} else {
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_video");
$this->bot->sendVideo(
$this->message->getChat()->getId(),
"https://crabrave.boringcactus.com/render?text=" . urlencode($m->getText()) . "&ext=mp4&style=" . $this->mode,
null,
null,
$this->message->getMessageId(),
null,
null,
"HTML"
);
}
}
}

26
handlers/Tpdne.php Normal file
View File

@ -0,0 +1,26 @@
<?php
class Tpdne extends Command
{
public static function exposedCommands(): array{
return [];
}
public function __construct(\TelegramBot\Api\Types\Message $message, \TelegramBot\Api\Client $bot)
{
parent::__construct($message, $bot);
}
public function execute(): void
{
$this->bot->sendChatAction($this->message->getChat()->getId(), "upload_photo");
$this->bot->sendPhoto(
$this->message->getChat()->getId(),
"https://thispersondoesnotexist.com/image?v=" . bin2hex(random_bytes(10)) . time(),
null,
$this->message->getMessageId(),
null,
null,
"HTML"
);
}
}