commit
c3109b2a50
23
README.md
23
README.md
@ -1,15 +1,22 @@
|
|||||||
telegram-bot
|
telegram-bot
|
||||||
============
|
============
|
||||||
|
|
||||||
Bot for telegram with [tg](https://github.com/vysheng/tg).
|
A telegram bot using https://github.com/vysheng/tg.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Requirements
|
||||||
```bash
|
```bash
|
||||||
# Tested on Ubuntu 14.04
|
# Tested on Ubuntu 14.04, for other OSs check out https://github.com/vysheng/tg#installation
|
||||||
sudo apt-get install lua-socket libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev fortune curl
|
$ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev fortune curl luarocks
|
||||||
git clone https://github.com/yagop/telegram-bot.git && cd telegram-bot
|
```
|
||||||
git submodule update --init --recursive
|
|
||||||
cd tg
|
* Clone the repo & compile the telegram library
|
||||||
./configure && make
|
```bash
|
||||||
../launch.sh
|
$ git clone https://github.com/yagop/telegram-bot --recursive && cd telegram-bot/tg
|
||||||
|
$ ./configure && make
|
||||||
|
$ cd .. && ./launch.sh # Will ask you for a telegram enabled number phone & confirmation code.
|
||||||
```
|
```
|
||||||
|
|
||||||
Command list
|
Command list
|
||||||
|
34
bot/bot.lua
34
bot/bot.lua
@ -16,9 +16,11 @@ function on_msg_receive (msg)
|
|||||||
else
|
else
|
||||||
if is_image_url(msg.text) then
|
if is_image_url(msg.text) then
|
||||||
send_image_from_url (msg)
|
send_image_from_url (msg)
|
||||||
|
elseif is_youtube_url(msg.text) then
|
||||||
|
send_youtube_thumbnail(msg.text)
|
||||||
else
|
else
|
||||||
if is_file_url(msg.text) then
|
if is_file_url(msg.text) then
|
||||||
send_file_from_url (msg)
|
send_file_from_url(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -67,6 +69,20 @@ function is_image_url(text)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function is_youtube_url(text)
|
||||||
|
-- http://stackoverflow.com/questions/19377262/regex-for-youtube-url
|
||||||
|
not_full_yt_url = string.match(text, "youtube.com/watch%?v=([A-Za-z0-9-]*)") == nil
|
||||||
|
not_short_yt_url = string.match(text, "youtu.be/([A-Za-z0-9-]*)") == nil
|
||||||
|
yt = full_yt_url or short_yt_url
|
||||||
|
return yt
|
||||||
|
end
|
||||||
|
|
||||||
|
function send_youtube_thumbnail(msg)
|
||||||
|
yt_thumbnail = "http://img.youtube.com/vi/".. string.match(msg.text, "([A-Za-z0-9-]*)").."/hqdefault.jpg"
|
||||||
|
file = download_to_file(yt_thumbnail)
|
||||||
|
send_photo(get_receiver(msg), file, ok_cb, false)
|
||||||
|
end
|
||||||
|
|
||||||
function is_file_url(text)
|
function is_file_url(text)
|
||||||
last = string.get_last_word(text)
|
last = string.get_last_word(text)
|
||||||
extension = string.get_extension_from_filename(last)
|
extension = string.get_extension_from_filename(last)
|
||||||
@ -106,14 +122,14 @@ function do_action(msg)
|
|||||||
meaning = getDulcinea(text)
|
meaning = getDulcinea(text)
|
||||||
send_msg(receiver, meaning, ok_cb, false)
|
send_msg(receiver, meaning, ok_cb, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.starts(msg.text, '!9gag') then
|
if string.starts(msg.text, '!9gag') then
|
||||||
url, title = get_9GAG()
|
url, title = get_9GAG()
|
||||||
file_path = download_to_file(url)
|
file_path = download_to_file(url)
|
||||||
send_photo(receiver, file_path, ok_cb, false)
|
send_photo(receiver, file_path, ok_cb, false)
|
||||||
send_msg(receiver, title, ok_cb, false)
|
send_msg(receiver, title, ok_cb, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.starts(msg.text, '!fortune') then
|
if string.starts(msg.text, '!fortune') then
|
||||||
text = run_bash('fortune')
|
text = run_bash('fortune')
|
||||||
|
Reference in New Issue
Block a user