Skip to content

Instantly share code, notes, and snippets.

@smaznet
Created June 5, 2017 10:18
Show Gist options
  • Save smaznet/8126ea9e31e161f37b71bffbca4799f3 to your computer and use it in GitHub Desktop.
Save smaznet/8126ea9e31e161f37b71bffbca4799f3 to your computer and use it in GitHub Desktop.
ToFarsiBot
<?php
function doCnvert($text)
{
$text = remove_emoji($text);
$text = strtolower($text);
$result = file_get_contents("http://www.behnevis.com/php/convert.php?farsi=" . urlencode($text) . "&resulttype=json&responsetime=-1");
$res = implode(" ", array_values(json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $result), true)));
return $res;
}
function remove_emoji($text)
{
return preg_replace('/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F6FF}][\x{FE00}-\x{FEFF}]?/u', '', $text);
}
require("core/telegramhelper.php");// clone from : https://github.com/smaznet/simplePhpBot
$data = json_decode(file_get_contents("php://input"));
$Tl = new telegramhelper("token");
if (isset($data->message)) {
if (isset($data->caption)) {
$text = $data->caption;
$data->caption = doCnvert($text);
}
if (isset($data->message->text)) {
$text = $data->message->text;
$data->message->text = doCnvert($text);
}
$Tl->forwardMessageWithoutHeader($data->message, $data->message->chat->id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment