From c25820c8059b8b7a4f119bf96fdedff48e43a0b1 Mon Sep 17 00:00:00 2001 From: Yago Date: Wed, 10 Dec 2014 12:19:50 +0100 Subject: [PATCH 1/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 48a11ff..b08cffe 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Installation ```bash # Tested on Ubuntu 14.04, for other OSs check out https://github.com/vysheng/tg#installation -$ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev +$ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev unzip git $ cd /tmp $ wget http://luarocks.org/releases/luarocks-2.2.0.tar.gz $ tar -xzvf luarocks-2.2.0.tar.gz @@ -54,4 +54,4 @@ $ git clone git@github.com:yagop/telegram-bot.git --recursive $ cd telegram-bot/tg $ ./configure && make $ cd .. && ./launch.sh # Will ask you for a phone number & confirmation code. -``` \ No newline at end of file +``` From 792ad233c29aa5eec6c9e8da3bb3ecdd95631f35 Mon Sep 17 00:00:00 2001 From: Yago Date: Wed, 10 Dec 2014 12:25:18 +0100 Subject: [PATCH 2/3] resolves #18 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b08cffe..2dc2173 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ $ sudo luarocks install luasocket ```bash # After those dependencies, lets install the bot $ cd $HOME -$ git clone git@github.com:yagop/telegram-bot.git --recursive +$ git clone https://github.com/yagop/telegram-bot.git --recursive $ cd telegram-bot/tg $ ./configure && make $ cd .. && ./launch.sh # Will ask you for a phone number & confirmation code. From fb138cabf3d9471b8ba2f8366f79740b967aa539 Mon Sep 17 00:00:00 2001 From: yago Date: Thu, 11 Dec 2014 22:12:12 +0100 Subject: [PATCH 3/3] When text exceds 4096 chars, sends in multiple msgs --- bot/bot.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index 1392564..4d099db 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -72,7 +72,7 @@ result = desc.run(msg, matches) print(" sending", result) if (result) then - send_msg(receiver, result, ok_cb, false) + _send_msg(receiver, result) return end end @@ -80,6 +80,24 @@ end end + -- If text is longer than 4096 chars, send multiple msg. + -- https://core.telegram.org/method/messages.sendMessage + function _send_msg( destination, text) + local msg_text_max = 4096 + local len = string.len(text) + local iterations = math.ceil(len / msg_text_max) + + for i = 1, iterations, 1 do + print ("iteracion: "..i) + local inital_c = i * msg_text_max - msg_text_max + local final_c = i * msg_text_max + -- dont worry about if text length < msg_text_max + local text_msg = string.sub(text,inital_c,final_c) + send_msg(destination, text_msg, ok_cb, false) + end + end + + function load_config() local f = assert(io.open('./bot/config.json', "r")) local c = f:read "*a"