From e3a9d2fc38323c177919bf8775421c7835c178c4 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 11:45:36 +0300
Subject: [PATCH 1/7] ololo
---
telebot.php | 72 +++++++++++++++++------------------------------------
1 file changed, 23 insertions(+), 49 deletions(-)
diff --git a/telebot.php b/telebot.php
index 10c2c04..2f52460 100644
--- a/telebot.php
+++ b/telebot.php
@@ -1,33 +1,9 @@
-ChatID();
-function checkArr($arr)
-{
- $check = array_filter($arr, function($k)
- {
+function checkArr($arr) {
+ $check = array_filter($arr, function($k) {
global $mb_text;
return mb_stripos($mb_text, $k) !== false;
});
@@ -61,23 +35,23 @@ function checkArr($arr)
);
$telegram->sendMessage($content);
}
+// Месасы
+if ($text == "/mem" || $text == "/meme") {
+ $opts = array('http' => array('method' => "GET",'header' => "Cookie: beget=begetok;\r\n"));
+ $context = stream_context_create($opts);
+ $data = file_get_contents("http://admem.ru/rndm", false, $context);
+ preg_match_all("/\
/", $data, $matches);
+ $pic = $matches[1][array_rand($matches[1], 1)];
+ $telegram->sendPhoto(array(
+ 'chat_id' => $chat_id,
+ 'photo' => "http://" . $pic
+ ));
+}
// Шутки с баша
if ($text == "/bash" OR $text == "/bash@Turn_Bot") {
$html = file_get_contents('http://bash.im/forweb/?u');
- $sim = array(
- "document.write(borq);",
- "var borq='';",
- "borq +=",
- """,
- "<' + 'br>"
- );
- $rep = array(
- "",
- "",
- "",
- "'",
- "\n"
- );
+ $sim = array("document.write(borq);","var borq='';","borq +=",""","<' + 'br>");
+ $rep = array("","","","'","\n");
$html = explode(' ]', substr(strip_tags(str_replace($sim, $rep, $html), '\n'), 4, -30));
$content = array(
'chat_id' => $chat_id,
@@ -189,7 +163,7 @@ function checkArr($arr)
));
}
//Котик
-if ($text == "/cat" OR $text == "/cat@Turn_Bot") {
+if (checkArr($find_cats) === true) {
$rss = simplexml_load_file("http://thecatapi.com/api/images/get?format=xml");
$reply = (get_headers($rss->data->images->image->url) !== false) ? $rss->data->images->image->url : "Котик сдох. Попробуй еще раз.";
$telegram->sendMessage(array(
@@ -240,4 +214,4 @@ function checkArr($arr)
);
$telegram->sendMessage($content);
}
-?>
\ No newline at end of file
+?>
\ No newline at end of file
From 90271a4702ca45fc43fbb98ec45482812e722f08 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 12:05:42 +0300
Subject: [PATCH 2/7] find_meme
---
telebot.php | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/telebot.php b/telebot.php
index 2f52460..3ef70c1 100644
--- a/telebot.php
+++ b/telebot.php
@@ -1,9 +1,10 @@
- sendMessage($content);
}
// Месасы
-if ($text == "/mem" || $text == "/meme") {
+if ($text == "/mem" || $text == "/meme" || checkArr($find_meme) === true) {
$opts = array('http' => array('method' => "GET",'header' => "Cookie: beget=begetok;\r\n"));
$context = stream_context_create($opts);
$data = file_get_contents("http://admem.ru/rndm", false, $context);
@@ -214,4 +215,4 @@ function checkArr($arr) {
);
$telegram->sendMessage($content);
}
-?>
\ No newline at end of file
+?>
From 41c88eaa0bdefbea1098e6c8400a02a480eb2070 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 12:38:48 +0300
Subject: [PATCH 3/7] timers
---
telebot.php | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/telebot.php b/telebot.php
index 3ef70c1..39c7853 100644
--- a/telebot.php
+++ b/telebot.php
@@ -8,10 +8,25 @@
$bot_id = "";
$yandtrankey = "";
$openwethid = "";
+$s_timer = 10;
+
+
$telegram = new Telegram($bot_id);
$text = $telegram->Text();
$mb_text = mb_strtolower($text, 'utf-8');
$chat_id = $telegram->ChatID();
+$s_timers = (object)array('boobs' => 0, 'butts' => 0, 'cats' => 0, 'meme' => 0);
+$s_timers = file_exists("timers.txt") ? json_decode(file_get_contents("timers.txt")) : $s_timers;
+
+function checkTimer($type, $timers, $s_timer)
+{
+ if ($timers->$type + $s_timer < time()) {
+ $timers->$type = time();
+ file_put_contents("timers.txt", json_encode($timers));
+ return true;
+ }
+ return false;
+}
function checkArr($arr) {
$check = array_filter($arr, function($k) {
@@ -37,7 +52,7 @@ function checkArr($arr) {
$telegram->sendMessage($content);
}
// Месасы
-if ($text == "/mem" || $text == "/meme" || checkArr($find_meme) === true) {
+if ((in_array($text, array("/mem", "/meme")) || checkArr($find_meme) === true) && checkTimer('meme', $s_timers, $s_timer)) {
$opts = array('http' => array('method' => "GET",'header' => "Cookie: beget=begetok;\r\n"));
$context = stream_context_create($opts);
$data = file_get_contents("http://admem.ru/rndm", false, $context);
@@ -164,7 +179,7 @@ function checkArr($arr) {
));
}
//Котик
-if (checkArr($find_cats) === true) {
+if (checkArr($find_cats) === true && checkTimer('cats', $s_timers, $s_timer)) {
$rss = simplexml_load_file("http://thecatapi.com/api/images/get?format=xml");
$reply = (get_headers($rss->data->images->image->url) !== false) ? $rss->data->images->image->url : "Котик сдох. Попробуй еще раз.";
$telegram->sendMessage(array(
@@ -173,7 +188,7 @@ function checkArr($arr) {
));
}
// Сиськи
-if (checkArr($find_boobs) === true) {
+if (checkArr($find_boobs) === true && checkTimer('boobs', $s_timers, $s_timer)) {
$data = json_decode(file_get_contents("http://api.oboobs.ru/boobs/1/1/random/"));
$telegram->sendPhoto(array(
'chat_id' => $chat_id,
@@ -181,7 +196,7 @@ function checkArr($arr) {
));
}
// Жопки
-if (checkArr($find_butts) === true) {
+if (checkArr($find_butts) === true && checkTimer('butts', $s_timers, $s_timer)) {
$data = json_decode(file_get_contents("http://api.obutts.ru/butts/1/1/random/"));
$telegram->sendPhoto(array(
'chat_id' => $chat_id,
From d55fb0ebafd2280f0bd038b4d1525b7b70ead937 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 14:01:21 +0300
Subject: [PATCH 4/7] oop
---
telebot.php | 563 +++++++++++++++++++++++++++++++---------------------
1 file changed, 338 insertions(+), 225 deletions(-)
diff --git a/telebot.php b/telebot.php
index 39c7853..134c981 100644
--- a/telebot.php
+++ b/telebot.php
@@ -1,233 +1,346 @@
Text();
-$mb_text = mb_strtolower($text, 'utf-8');
-$chat_id = $telegram->ChatID();
-$s_timers = (object)array('boobs' => 0, 'butts' => 0, 'cats' => 0, 'meme' => 0);
-$s_timers = file_exists("timers.txt") ? json_decode(file_get_contents("timers.txt")) : $s_timers;
-
-function checkTimer($type, $timers, $s_timer)
-{
- if ($timers->$type + $s_timer < time()) {
- $timers->$type = time();
- file_put_contents("timers.txt", json_encode($timers));
- return true;
- }
- return false;
-}
-
-function checkArr($arr) {
- $check = array_filter($arr, function($k) {
- global $mb_text;
- return mb_stripos($mb_text, $k) !== false;
- });
- return count($check) > 0;
-}
-// Помощь
-if ($text == "/help" OR $text == "/help@Turn_Bot") {
- $reply = " /help - список команд
- /bash - шуткануть с баша
- /cur - погрустить с курсом
- /news - 5 свежих новостей с медузы
- /tr - яндекс.переводчик. Жми команду для помощи.
- /we - погода. Жми команду для помощи.
- /advice - спросить совета (кд 1 мин)
- /cat - котик";
- $content = array(
- 'chat_id' => $chat_id,
- 'text' => $reply
- );
- $telegram->sendMessage($content);
-}
-// Месасы
-if ((in_array($text, array("/mem", "/meme")) || checkArr($find_meme) === true) && checkTimer('meme', $s_timers, $s_timer)) {
- $opts = array('http' => array('method' => "GET",'header' => "Cookie: beget=begetok;\r\n"));
- $context = stream_context_create($opts);
- $data = file_get_contents("http://admem.ru/rndm", false, $context);
- preg_match_all("/\
/", $data, $matches);
- $pic = $matches[1][array_rand($matches[1], 1)];
- $telegram->sendPhoto(array(
- 'chat_id' => $chat_id,
- 'photo' => "http://" . $pic
- ));
-}
-// Шутки с баша
-if ($text == "/bash" OR $text == "/bash@Turn_Bot") {
- $html = file_get_contents('http://bash.im/forweb/?u');
- $sim = array("document.write(borq);","var borq='';","borq +=",""","<' + 'br>");
- $rep = array("","","","'","\n");
- $html = explode(' ]', substr(strip_tags(str_replace($sim, $rep, $html), '\n'), 4, -30));
- $content = array(
- 'chat_id' => $chat_id,
- 'text' => html_entity_decode($html[1])
- );
- $telegram->sendMessage($content);
-}
-//Курс валюты
-if ($text == "/cur" OR $text == "/cur@Turn_Bot") {
- $cur = simplexml_load_file("http://www.cbr.ru/scripts/XML_daily.asp?");
- $usd = $cur->Valute[10]->Name . " " . $cur->Valute[10]->Value;
- $eur = $cur->Valute[11]->Name . " " . $cur->Valute[11]->Value;
- $pln = $cur->Valute[19]->Name . " " . $cur->Valute[19]->Value;
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $usd . "\n" . $eur . "\n" . $pln
- ));
-}
-//Новости
-if ($text == "/news" OR $text == "/news@Turn_Bot") {
- $rss = simplexml_load_file("https://meduza.io/rss/all");
- $result = '';
- for ($i = 0; $i < 6; $i++) {
- $title = $rss->channel->item[$i]->title;
- $link = $rss->channel->item[$i]->link;
- $result .= $i . ") [" . trim($title) . "](" . $link . ")\n";
- }
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $result,
- 'parse_mode' => 'Markdown',
- 'disable_web_page_preview' => 'true'
- ));
-}
-//Гитлер и все, что к нему относится
-$hitlers = array(
- 'CAADAgADTAIAAiHtuwM0w5oWdrwUsAI',
- 'BQADAgADPgIAAiHtuwPNMjQkRQEERwI',
- 'BQADAgADMgIAAiHtuwO7d0YhJHL79AI',
- 'BQADAgAD1wMAAiHtuwOg8Q_qBaHrbAI',
- 'BQADAgAD5wMAAiHtuwN2AAFEAsKmcN4C',
- 'BQADAgADRAIAAiHtuwM4RQnJhcQXrwI',
- 'BQADBAADsAADcKvVBCcMLL-Z2FfrAg',
- 'BQADAgADLAIAAiHtuwPRAt2H7R4JbQI',
- 'BQADAgADMAIAAiHtuwOdxr-cmmlPLwI',
- 'BQADAgADSAIAAiHtuwO8cAJFZVDO6wI',
- 'CAADAgADLAIAAiHtuwPRAt2H7R4JbQI',
- 'CAADAgADLgIAAiHtuwNdwzbZsxYrtAI',
- 'CAADAgADMAIAAiHtuwOdxr-cmmlPLwI',
- 'CAADAgADMgIAAiHtuwO7d0YhJHL79AI',
- 'CAADAgADNAIAAiHtuwOrFz1Ys75vngI',
- 'CAADAgADOAIAAiHtuwMs7mMiyp_LGQI',
- 'CAADAgADPgIAAiHtuwPNMjQkRQEERwI',
- 'CAADAgADQAIAAiHtuwPJ8ab-ioHcXQI',
- 'CAADAgADRAIAAiHtuwM4RQnJhcQXrwI',
- 'CAADAgADSAIAAiHtuwO8cAJFZVDO6wI',
- 'CAADAgADTgIAAiHtuwPIk696OrWIhgI',
- 'CAADAgADxQMAAiHtuwMNjB9tfln8QwI',
- 'CAADAgADxwMAAiHtuwMfIaXCl3_ZSQI',
- 'CAADAgADyQMAAiHtuwOUVmQX3cuc9wI',
- 'CAADAgADzQMAAiHtuwMwC3wxDSKU3QI',
- 'CAADAgADzwMAAiHtuwPIImB34jFF6wI',
- 'CAADAgAD0wMAAiHtuwMjoZFV2xiQIwI',
- 'CAADAgAD2QMAAiHtuwNSSISIiiunBgI',
- 'CAADAgAD2wMAAiHtuwMMX7zpS7REfQI',
- 'CAADAgAD3QMAAiHtuwPI0dsWzZZDEQI',
- 'CAADAgAD3wMAAiHtuwMly8RQMXZLCgI',
- 'CAADAgAD4QMAAiHtuwOb2b3uZxbBVgI',
- 'CAADAgAD5wMAAiHtuwN2AAFEAsKmcN4C',
- 'CAADAgAD6QMAAiHtuwP_7MG90BPVGwI'
+$app = new turnBot(array(
+ 'bot_id' => '',
+ 'yandex_translate_key' => '',
+ 'open_wheather_key' => ''
+ )
);
-if (checkArr($find_hitlers) === true) {
- $content = array(
- 'chat_id' => $chat_id,
- 'sticker' => $hitlers[rand(0, 33)]
+
+class turnBot {
+ private $find_types = array(
+ 'hitler' => array("гитлер","рейх","зига","hitler","1488","рейх","жечь евреев","жги евреев","холокост"),
+ 'boobs' => array("сиськи","сисек","сисечки","сисяндры","сисюли","/boobs","/boobs@Turn_Bot"),
+ 'butts' => array("жопа","попа","попка","жопка","жопо","жопунька","кардан","кардашьян","седло"),
+ 'cats' => array("кот","котейка","котюня","шерстяной","киса","кошко","котэ"),
+ 'meme' => array("мемас","баянчег","боян","баянист")
);
- $telegram->sendSticker($content);
-}
-//Переводчик
-$trpos = mb_stripos($text, "/tr");
-if ($trpos !== false) {
- $text = explode(' ', $text);
- $lang = $text[1];
- $text = urlencode(join(' ', array_slice($text, 2)));
- $url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" . $yandtrankey . "&text=" . $text . "&lang=" . $lang;
- $data = json_decode(file_get_contents($url));
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $data->text[0]
- ));
-}
-// Хелп по переводчику
-if ($text == "/tr" OR $text == "/tr@Turn_Bot") {
- $reply = "Помощь по переводчику.\n/tr [язык] [текст]\nЯзык на вотороый хотим перевести, исходный определяется автоматически.\n";
- $reply .= "Пример - /tr ru hello\n[Список языков](https://tech.yandex.ru/translate/doc/dg/concepts/api-overview-docpage/)";
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $reply,
- 'parse_mode' => 'Markdown',
- 'disable_web_page_preview' => 'true'
- ));
-}
-// Советы
-if ($text == "/advice" OR $text == "/advice@Turn_Bot") {
- $data = json_decode(file_get_contents("http://fucking-great-advice.ru/api/random"));
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => html_entity_decode($data->text)
- ));
-}
-//Котик
-if (checkArr($find_cats) === true && checkTimer('cats', $s_timers, $s_timer)) {
- $rss = simplexml_load_file("http://thecatapi.com/api/images/get?format=xml");
- $reply = (get_headers($rss->data->images->image->url) !== false) ? $rss->data->images->image->url : "Котик сдох. Попробуй еще раз.";
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $reply
- ));
-}
-// Сиськи
-if (checkArr($find_boobs) === true && checkTimer('boobs', $s_timers, $s_timer)) {
- $data = json_decode(file_get_contents("http://api.oboobs.ru/boobs/1/1/random/"));
- $telegram->sendPhoto(array(
- 'chat_id' => $chat_id,
- 'photo' => "http://media.oboobs.ru/" . $data[0]->preview
- ));
-}
-// Жопки
-if (checkArr($find_butts) === true && checkTimer('butts', $s_timers, $s_timer)) {
- $data = json_decode(file_get_contents("http://api.obutts.ru/butts/1/1/random/"));
- $telegram->sendPhoto(array(
- 'chat_id' => $chat_id,
- 'photo' => "http://media.obutts.ru/" . $data[0]->preview
- ));
-}
-//Погода
-$wepos = mb_stripos($text, "/we ");
-if ($wepos !== false) {
- $city = mb_strimwidth($text, 4, 500);
- $url = "http://api.openweathermap.org/data/2.5/weather?q=" . $city . "&lang=ru&units=metric&APPID=" . $openwethid;
- $data = json_decode(file_get_contents($url));
- $pressure = $data->main->pressure * 0.750064;
- $reply = $data->weather[0]->description . "\n";
- $reply .= "Температура: " . $data->main->temp . "°C\n";
- $reply .= "Давление: " . $pressure . "рт/ст\n";
- $reply .= "Влажность: " . $data->main->humidity . "%\n";
- $telegram->sendMessage(array(
- 'chat_id' => $chat_id,
- 'text' => $reply
- ));
-}
-// Хелп по погоде
-if ($text == "/we" OR $text == "/we@Turn_Bot") {
- $reply = "Для тех, кому лень идти до окна.\n/we [город]\nПример - /we Калининград";
- $content = array(
- 'chat_id' => $chat_id,
- 'text' => $reply,
- 'parse_mode' => 'Markdown',
- 'disable_web_page_preview' => 'true'
+ private $hitlers = array(
+ 'CAADAgADTAIAAiHtuwM0w5oWdrwUsAI',
+ 'BQADAgADPgIAAiHtuwPNMjQkRQEERwI',
+ 'BQADAgADMgIAAiHtuwO7d0YhJHL79AI',
+ 'BQADAgAD1wMAAiHtuwOg8Q_qBaHrbAI',
+ 'BQADAgAD5wMAAiHtuwN2AAFEAsKmcN4C',
+ 'BQADAgADRAIAAiHtuwM4RQnJhcQXrwI',
+ 'BQADBAADsAADcKvVBCcMLL-Z2FfrAg',
+ 'BQADAgADLAIAAiHtuwPRAt2H7R4JbQI',
+ 'BQADAgADMAIAAiHtuwOdxr-cmmlPLwI',
+ 'BQADAgADSAIAAiHtuwO8cAJFZVDO6wI',
+ 'CAADAgADLAIAAiHtuwPRAt2H7R4JbQI',
+ 'CAADAgADLgIAAiHtuwNdwzbZsxYrtAI',
+ 'CAADAgADMAIAAiHtuwOdxr-cmmlPLwI',
+ 'CAADAgADMgIAAiHtuwO7d0YhJHL79AI',
+ 'CAADAgADNAIAAiHtuwOrFz1Ys75vngI',
+ 'CAADAgADOAIAAiHtuwMs7mMiyp_LGQI',
+ 'CAADAgADPgIAAiHtuwPNMjQkRQEERwI',
+ 'CAADAgADQAIAAiHtuwPJ8ab-ioHcXQI',
+ 'CAADAgADRAIAAiHtuwM4RQnJhcQXrwI',
+ 'CAADAgADSAIAAiHtuwO8cAJFZVDO6wI',
+ 'CAADAgADTgIAAiHtuwPIk696OrWIhgI',
+ 'CAADAgADxQMAAiHtuwMNjB9tfln8QwI',
+ 'CAADAgADxwMAAiHtuwMfIaXCl3_ZSQI',
+ 'CAADAgADyQMAAiHtuwOUVmQX3cuc9wI',
+ 'CAADAgADzQMAAiHtuwMwC3wxDSKU3QI',
+ 'CAADAgADzwMAAiHtuwPIImB34jFF6wI',
+ 'CAADAgAD0wMAAiHtuwMjoZFV2xiQIwI',
+ 'CAADAgAD2QMAAiHtuwNSSISIiiunBgI',
+ 'CAADAgAD2wMAAiHtuwMMX7zpS7REfQI',
+ 'CAADAgAD3QMAAiHtuwPI0dsWzZZDEQI',
+ 'CAADAgAD3wMAAiHtuwMly8RQMXZLCgI',
+ 'CAADAgAD4QMAAiHtuwOb2b3uZxbBVgI',
+ 'CAADAgAD5wMAAiHtuwN2AAFEAsKmcN4C',
+ 'CAADAgAD6QMAAiHtuwP_7MG90BPVGwI'
);
- $telegram->sendMessage($content);
+ private $s_timer = 10;
+ private $s_timers = array('boobs' => 0, 'butts' => 0, 'cats' => 0, 'meme' => 0);
+ private $telegram, $bot_id, $yandtrankey, $openwethid, $chat_id, $text, $mb_text;
+
+ function __construct($opts)
+ {
+ $this->telegram = new Telegram($opts['bot_id']);
+ $this->text = $this->telegram->Text();
+ $this->mb_text = mb_strtolower($this->text, 'utf-8');
+ $this->chat_id = $this->telegram->ChatID();
+ $this->yandtrankey = $opts['yandex_translate_key'];
+ $this->openwethid = $opts['open_wheather_key'];
+ $this->s_timers = file_exists("timers.txt") ? json_decode(file_get_contents("timers.txt")) : (object)$this->s_timers;
+ $this->proceedText();
+ }
+
+ function _checkTimer($type)
+ {
+ if($this->s_timers->$type + $this->s_timer < time())
+ {
+ $this->s_timers->$type = time();
+ file_put_contents("timers.txt", json_encode($this->s_timers));
+ return true;
+ }
+ return false;
+ }
+
+ function _checkArr($type)
+ {
+ $check = array_filter($this->find_types[$type], array($this, '_arrFilter'));
+ return count($check) > 0;
+ }
+
+ function _arrFilter($k)
+ {
+ return mb_stripos($this->mb_text, $k) !== false;
+ }
+
+ function _sendText($text, $opts = array())
+ {
+ $content = array(
+ 'chat_id' => $this->chat_id,
+ 'text' => $text
+ );
+ if(count($opts) > 0)
+ {
+ $content = array_merge($content, $opts);
+ }
+ $this->telegram->sendMessage($content);
+ }
+
+ function _sendPhoto($url)
+ {
+ $this->telegram->sendPhoto(array(
+ 'chat_id' => $this->chat_id,
+ 'photo' => $url
+ ));
+ }
+
+ function _sendSticker($sticker)
+ {
+ $content = array(
+ 'chat_id' => $chat_id,
+ 'sticker' => $sticker
+ );
+ $this->telegram->sendSticker($content);
+ }
+
+ function proceedText()
+ {
+ switch(trim($this->text))
+ {
+ case "/help":
+ case "/help@Turn_Bot":
+ return $this->helpMessage();
+ break;
+ case "/mem":
+ case "/meme":
+ return $this->memeMessage();
+ break;
+ case "/bash":
+ case "/bash@Turn_Bot":
+ return $this->bashMessage();
+ break;
+ case "/cur":
+ case "/cur@Turn_Bot":
+ return $this->curMessage();
+ break;
+ case "/news":
+ case "/news@Turn_Bot":
+ return $this->newsMessage();
+ break;
+ case "/tr":
+ case "/tr@Turn_Bot":
+ return $this->trHelpMessage();
+ break;
+ case "/advice":
+ case "/advice@Turn_Bot":
+ return $this->adviceMessage();
+ break;
+ case "/we":
+ case "/we@Turn_Bot":
+ return $this->weHelpMessage();
+ break;
+ default:
+ return $this->checkNonStandart();
+ }
+ }
+
+ function checkNonStandart()
+ {
+ foreach(array('hitler', 'boobs', 'butts', 'cats', 'meme') as $type)
+ {
+ if($this->_checkArr($type))
+ $this->proceedNonStandart($type);
+ }
+ $arr_text = explode(' ', $this->text);
+ if(count($arr_text) < 1)
+ return false;
+ switch($arr_text[0])
+ {
+ case "/tr":
+ return $this->trMessage($arr_text);
+ case "/we":
+ return $this->weMessage();
+ }
+ }
+
+ function proceedNonStandart($type)
+ {
+ switch($type)
+ {
+ case "hitler":
+ return $this->hitlerMessage();
+ case "boobs":
+ return $this->boobsMessage();
+ case "butts":
+ return $this->buttsMessage();
+ case "cats":
+ return $this->catsMessage();
+ case "meme":
+ return $this->memeMessage();
+ }
+ }
+
+ function trMessage($arr_text)
+ {
+ $text = urlencode(join(' ', array_slice($arr_text, 2)));
+ $url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" . $this->yandtrankey . "&text=" . $text . "&lang=" . $arr_text[1];
+ $data = json_decode(file_get_contents($url));
+ $this->sendMessage($data->text[0]);
+ }
+
+ function weMessage()
+ {
+ $city = mb_strimwidth($this->text, 4, 500);
+ $url = "http://api.openweathermap.org/data/2.5/weather?q=" . $city . "&lang=ru&units=metric&APPID=" . $thisa->openwethid;
+ $data = json_decode(file_get_contents($url));
+ $pressure = $data->main->pressure * 0.750064;
+ $reply = $data->weather[0]->description . "\n";
+ $reply .= "Температура: " . $data->main->temp . "°C\n";
+ $reply .= "Давление: " . $pressure . "рт/ст\n";
+ $reply .= "Влажность: " . $data->main->humidity . "%\n";
+ $this->sendMessage($reply);
+ }
+
+ function hitlerMessage()
+ {
+ $this->sendSticker($this->hitlers[rand(0, (count($this->hitlers) - 1))]);
+ }
+
+ function boobsMessage()
+ {
+ if(!$this->_checkTimer('boobs'))
+ return false;
+ $data = json_decode(file_get_contents("http://api.oboobs.ru/boobs/1/1/random/"));
+ $this->sendPhoto("http://media.oboobs.ru/" . $data[0]->preview);
+ }
+
+ function buttsMessage()
+ {
+ if(!$this->_checkTimer('butts'))
+ return false;
+ $data = json_decode(file_get_contents("http://api.obutts.ru/butts/1/1/random/"));
+ $this->sendPhoto("http://media.obutts.ru/" . $data[0]->preview);
+ }
+
+ function catsMessage()
+ {
+ if(!$this->_checkTimer('cats'))
+ return false;
+ $rss = simplexml_load_file("http://thecatapi.com/api/images/get?format=xml");
+ $reply = (get_headers($rss->data->images->image->url) !== false) ? $rss->data->images->image->url : "Котик сдох. Попробуй еще раз.";
+ $this->sendMessage($reply);
+ }
+
+ function helpMessage()
+ {
+ $helps = array(
+ '/help - список команд',
+ '/bash - шуткануть с баша',
+ '/cur - погрустить с курсом',
+ '/news - 5 свежих новостей с медузы',
+ '/tr - яндекс.переводчик. Жми команду для помощи',
+ '/we - погода. Жми команду для помощи',
+ '/advice - спросить совета',
+ '/cat - котик',
+ '/mem - мемас'
+ );
+ $this->sendMessage(join("\n", $helps));
+ }
+
+ function memeMessage()
+ {
+ if(!$this->_checkTimer('meme'))
+ return false;
+ $opts = array('http' => array('method' => "GET",'header' => "Cookie: beget=begetok;\r\n"));
+ $context = stream_context_create($opts);
+ $data = file_get_contents("http://admem.ru/rndm", false, $context);
+ preg_match_all("/\
/", $data, $matches);
+ $pic = $matches[1][array_rand($matches[1], 1)];
+ $this->sendPhoto('http://'.$pic);
+ }
+
+ function bashMessage()
+ {
+ $html = file_get_contents('http://bash.im/forweb/?u');
+ $sim = array("document.write(borq);","var borq='';","borq +=",""","<' + 'br>");
+ $rep = array("","","","'","\n");
+ $html = explode(' ]', substr(strip_tags(str_replace($sim, $rep, $html), '\n'), 4, -30));
+ $this->sendMessage(html_entity_decode($html[1]));
+ }
+
+ function curMessage()
+ {
+ $cur = simplexml_load_file("http://www.cbr.ru/scripts/XML_daily.asp?");
+ $usd = $cur->Valute[10]->Name . " " . $cur->Valute[10]->Value;
+ $eur = $cur->Valute[11]->Name . " " . $cur->Valute[11]->Value;
+ $pln = $cur->Valute[19]->Name . " " . $cur->Valute[19]->Value;
+ $this->sendMessage($usd . "\n" . $eur . "\n" . $pln);
+ }
+
+ function newsMessage()
+ {
+ $rss = simplexml_load_file("https://meduza.io/rss/all");
+ $result = '';
+ for ($i = 0; $i < 6; $i++) {
+ $title = $rss->channel->item[$i]->title;
+ $link = $rss->channel->item[$i]->link;
+ $result .= $i . ") [" . trim($title) . "](" . $link . ")\n";
+ }
+ $this->sendMessage($result, array(
+ 'parse_mode' => 'Markdown',
+ 'disable_web_page_preview' => 'true'
+ ));
+ }
+
+ function trHelpMessage()
+ {
+ $helps = array(
+ 'Помощь по переводчику.',
+ '/tr [язык] [текст]',
+ 'Язык на который хотим перевести, исходный определяется автоматически.',
+ 'Пример - /tr ru hello',
+ '[Список языков](https://tech.yandex.ru/translate/doc/dg/concepts/api-overview-docpage/)'
+ );
+ $this->sendMessage(join("\n", $helps), array(
+ 'parse_mode' => 'Markdown',
+ 'disable_web_page_preview' => 'true'
+ ));
+ }
+
+ function adviceMessage()
+ {
+ $data = json_decode(file_get_contents("http://fucking-great-advice.ru/api/random"));
+ $this->sendMessage(html_entity_decode($data->text));
+ }
+
+ function weHelpMessage()
+ {
+ $helps = array(
+ 'Для тех, кому лень идти до окна.',
+ '/we [город]',
+ 'Пример - /we Калининград'
+ );
+ $this->sendMessage(join("\n", $helps), array(
+ 'parse_mode' => 'Markdown',
+ 'disable_web_page_preview' => 'true'
+ ));
+ }
}
?>
From e9c0c1dc3caf98ee346c573b2c721084c2173a53 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 14:04:17 +0300
Subject: [PATCH 5/7] oop fix
---
telebot.php | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/telebot.php b/telebot.php
index 134c981..e5ae14e 100644
--- a/telebot.php
+++ b/telebot.php
@@ -202,7 +202,7 @@ function trMessage($arr_text)
$text = urlencode(join(' ', array_slice($arr_text, 2)));
$url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" . $this->yandtrankey . "&text=" . $text . "&lang=" . $arr_text[1];
$data = json_decode(file_get_contents($url));
- $this->sendMessage($data->text[0]);
+ $this->_sendText($data->text[0]);
}
function weMessage()
@@ -215,12 +215,12 @@ function weMessage()
$reply .= "Температура: " . $data->main->temp . "°C\n";
$reply .= "Давление: " . $pressure . "рт/ст\n";
$reply .= "Влажность: " . $data->main->humidity . "%\n";
- $this->sendMessage($reply);
+ $this->_sendText($reply);
}
function hitlerMessage()
{
- $this->sendSticker($this->hitlers[rand(0, (count($this->hitlers) - 1))]);
+ $this->_sendSticker($this->hitlers[rand(0, (count($this->hitlers) - 1))]);
}
function boobsMessage()
@@ -228,7 +228,7 @@ function boobsMessage()
if(!$this->_checkTimer('boobs'))
return false;
$data = json_decode(file_get_contents("http://api.oboobs.ru/boobs/1/1/random/"));
- $this->sendPhoto("http://media.oboobs.ru/" . $data[0]->preview);
+ $this->_sendPhoto("http://media.oboobs.ru/" . $data[0]->preview);
}
function buttsMessage()
@@ -236,7 +236,7 @@ function buttsMessage()
if(!$this->_checkTimer('butts'))
return false;
$data = json_decode(file_get_contents("http://api.obutts.ru/butts/1/1/random/"));
- $this->sendPhoto("http://media.obutts.ru/" . $data[0]->preview);
+ $this->_sendPhoto("http://media.obutts.ru/" . $data[0]->preview);
}
function catsMessage()
@@ -245,7 +245,7 @@ function catsMessage()
return false;
$rss = simplexml_load_file("http://thecatapi.com/api/images/get?format=xml");
$reply = (get_headers($rss->data->images->image->url) !== false) ? $rss->data->images->image->url : "Котик сдох. Попробуй еще раз.";
- $this->sendMessage($reply);
+ $this->_sendPhoto($reply);
}
function helpMessage()
@@ -261,7 +261,7 @@ function helpMessage()
'/cat - котик',
'/mem - мемас'
);
- $this->sendMessage(join("\n", $helps));
+ $this->_sendText(join("\n", $helps));
}
function memeMessage()
@@ -273,7 +273,7 @@ function memeMessage()
$data = file_get_contents("http://admem.ru/rndm", false, $context);
preg_match_all("/\
/", $data, $matches);
$pic = $matches[1][array_rand($matches[1], 1)];
- $this->sendPhoto('http://'.$pic);
+ $this->_sendPhoto('http://'.$pic);
}
function bashMessage()
@@ -282,7 +282,7 @@ function bashMessage()
$sim = array("document.write(borq);","var borq='';","borq +=",""","<' + 'br>");
$rep = array("","","","'","\n");
$html = explode(' ]', substr(strip_tags(str_replace($sim, $rep, $html), '\n'), 4, -30));
- $this->sendMessage(html_entity_decode($html[1]));
+ $this->_sendText(html_entity_decode($html[1]));
}
function curMessage()
@@ -291,7 +291,7 @@ function curMessage()
$usd = $cur->Valute[10]->Name . " " . $cur->Valute[10]->Value;
$eur = $cur->Valute[11]->Name . " " . $cur->Valute[11]->Value;
$pln = $cur->Valute[19]->Name . " " . $cur->Valute[19]->Value;
- $this->sendMessage($usd . "\n" . $eur . "\n" . $pln);
+ $this->_sendText($usd . "\n" . $eur . "\n" . $pln);
}
function newsMessage()
@@ -303,7 +303,7 @@ function newsMessage()
$link = $rss->channel->item[$i]->link;
$result .= $i . ") [" . trim($title) . "](" . $link . ")\n";
}
- $this->sendMessage($result, array(
+ $this->_sendText($result, array(
'parse_mode' => 'Markdown',
'disable_web_page_preview' => 'true'
));
@@ -318,7 +318,7 @@ function trHelpMessage()
'Пример - /tr ru hello',
'[Список языков](https://tech.yandex.ru/translate/doc/dg/concepts/api-overview-docpage/)'
);
- $this->sendMessage(join("\n", $helps), array(
+ $this->_sendText(join("\n", $helps), array(
'parse_mode' => 'Markdown',
'disable_web_page_preview' => 'true'
));
@@ -327,7 +327,7 @@ function trHelpMessage()
function adviceMessage()
{
$data = json_decode(file_get_contents("http://fucking-great-advice.ru/api/random"));
- $this->sendMessage(html_entity_decode($data->text));
+ $this->_sendText(html_entity_decode($data->text));
}
function weHelpMessage()
@@ -337,7 +337,7 @@ function weHelpMessage()
'/we [город]',
'Пример - /we Калининград'
);
- $this->sendMessage(join("\n", $helps), array(
+ $this->_sendText(join("\n", $helps), array(
'parse_mode' => 'Markdown',
'disable_web_page_preview' => 'true'
));
From 395908d19bad63e47a16959369800ed7be5d06ec Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 14:30:18 +0300
Subject: [PATCH 6/7] fixfix
---
telebot.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/telebot.php b/telebot.php
index e5ae14e..b163ddc 100644
--- a/telebot.php
+++ b/telebot.php
@@ -114,7 +114,7 @@ function _sendPhoto($url)
function _sendSticker($sticker)
{
$content = array(
- 'chat_id' => $chat_id,
+ 'chat_id' => $this->chat_id,
'sticker' => $sticker
);
$this->telegram->sendSticker($content);
From 0fee466853bcc1a2e11e4321b1852e964766d1d0 Mon Sep 17 00:00:00 2001
From: fedorovvl <31754742+fedorovvl@users.noreply.github.com>
Date: Sun, 15 Oct 2017 19:52:37 +0300
Subject: [PATCH 7/7] cats fix
---
telebot.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/telebot.php b/telebot.php
index b163ddc..b63d450 100644
--- a/telebot.php
+++ b/telebot.php
@@ -140,6 +140,10 @@ function proceedText()
case "/cur@Turn_Bot":
return $this->curMessage();
break;
+ case "/cat":
+ case "/kitty":
+ return $this->catsMessage();
+ break;
case "/news":
case "/news@Turn_Bot":
return $this->newsMessage();