<?php
class DigitToText extends Intent {
function init(){
$this->name = "euroToman";
// preg_match('/(\d+((.|,)\d+)?)\S*\s*toman.*/', $input_line, $output_array);
$this->patterns[] = new Pattern('digit',"/(^[0-9]*$)/i");
$this->patterns[] = new Pattern('digit',"/(^[۰-۹]*$)/i");
}
function act(){
if(sizeof($this->data["entities"][0]["value"]) > 0){
$text = $this->getText();
$this->getIS()->getTG()->sendMessage($text,$this->tg->chat_id);
}
}
function getText(){
$number = $this->convertPersianNumbersToEnglish($this->data["entities"][0]["value"]);
$text = num2text($number);
$text .=PHP_EOL. convertNumberToWords($number);
$text .= PHP_EOL;
$text .= PHP_EOL;
$text .= "@TranslateGerman_bot😊";
return $text;
}
function actInline(){
$text = $this->data['inline_query']['query'];
if(sizeof($this->data["entities"])>0){
$textResponse = $this->getText();
$readyResult = [[
"type" => "article",
"id" => "3",
"title" => $text . " تبدیل عدد به حروف",
"message_text" => $textResponse . PHP_EOL . "@TranslateGerman_bot",
"cache_time" => 1
]];
$this->getIS()->getTG()->apiRequest("answerInlineQuery", array(
'inline_query_id' => $this->getIS()->getTG()->inline_message_id,
'results' => $readyResult,
'cache_time' => 1,
"parse_mode" => "html",
));
}
}
function convertPersianNumbersToEnglish($input)
{
$persian = ['۰', '۱', '۲', '۳', '۴', '٤', '۵', '٥', '٦', '۶', '۷', '۸', '۹'];
$english = [ 0 , 1 , 2 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , 7 , 8 , 9 ];
return str_replace($persian, $english, $input);
}
function getIntentID()
{
return 2;
}
}
?>