From 01d92dba1d8bc4ba44fd8995f2699e7d66d543c7 Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 12 Jan 2015 21:17:16 +0100 Subject: [PATCH 01/10] Update README.md --- README.md | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 077b642..4820f56 100644 --- a/README.md +++ b/README.md @@ -11,30 +11,25 @@ Multimedia - When user sends youtube URL, send to origin video image. ![http://i.imgur.com/0FGUvU0.png](http://i.imgur.com/0FGUvU0.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/zW7WWWt.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/kPK7paz.png) -Command list + +Default enabled commands ------------ ``` !9gag -> send random image from 9gag !echo [whatever] -> echoes the msg -!eur [USD] -> EURUSD market value -!uc3m -> Fortunes from Universidad Carlos III !get (value_name) -> retrieves variables saved with !set -say hello to [name] -> Says hello to someone -!help -> Lists all available commands -!img [topic] -> search image with Google API and sends it -!ping -> bot sends pong -!rae [word] -> Spanish dictionary !set [value_name] [data] -> Set value +!img [topic] -> search image with Google API and sends it +!loc (location) -> Gets information about a location, maplink and overview !stats -> Numer of messages by user !time [area] -> Displays the local time in an area -!tw [text] -> Sends a tweet !version -> Shows bot version -!weather (city) -> weather in that city (Madrid is default) +!google terms -> Searches Google +!help -> Lists all available commands ``` 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 unzip git @@ -52,12 +47,28 @@ $ sudo luarocks install luasocket $ cd $HOME $ git clone https://github.com/yagop/telegram-bot.git --recursive $ cd telegram-bot/tg -$ ./configure && make -$ cd .. +$ ./configure && make && cd .. +$ ./launch.sh # Will ask you for a phone number & confirmation code. +``` + +Enable more [`plugins`](https://github.com/yagop/telegram-bot/tree/master/plugins) +------------- +See the plugins list with `!plugins` command. + +Enable with `!plugins enable [name]`. + +Disable with `!plugins disable [plugin]`. + +Those commands require a privileged user, privileged users are defined inside `data/config.lua` (generated by the bot), stop de bot and edit if necessary. + + +Run it as a daemon +------------ +If your linux/unix comes with [upstart](http://upstart.ubuntu.com/) you can run the bot by this way +```bash $ sed -i "s/yourusername/$(whoami)/g" etc/telegram.conf $ sed -i "s_telegrambotpath_$(pwd)_g" etc/telegram.conf $ sudo cp etc/telegram.conf /etc/init/ -$ ./launch.sh # Will ask you for a phone number & confirmation code. ``` Contact me From 1322757009fddcf07cf9d419c0e4788ce8a860d5 Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 12 Jan 2015 21:26:24 +0100 Subject: [PATCH 02/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4820f56..162a156 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,9 @@ Enable more [`plugins`](https://github.com/yagop/telegram-bot/tree/master/plugin ------------- See the plugins list with `!plugins` command. -Enable with `!plugins enable [name]`. +Enable a disabled plugin by `!plugins enable [name]`. -Disable with `!plugins disable [plugin]`. +Disable an eanbled plugin by `!plugins disable [name]`. Those commands require a privileged user, privileged users are defined inside `data/config.lua` (generated by the bot), stop de bot and edit if necessary. From 0b55d3b6d3df4d0dda299b13641d126366af68f5 Mon Sep 17 00:00:00 2001 From: yago Date: Mon, 12 Jan 2015 22:29:59 +0100 Subject: [PATCH 03/10] GiphyAPI --- plugins/giphy.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plugins/giphy.lua diff --git a/plugins/giphy.lua b/plugins/giphy.lua new file mode 100644 index 0000000..ccf8697 --- /dev/null +++ b/plugins/giphy.lua @@ -0,0 +1,46 @@ +-- Idea by https://github.com/asdofindia/telegram-bot/ +-- See http://api.giphy.com/ + +function get_random_top() + local api_key = "dc6zaTOxFJmzC" -- public beta key + b = http.request("http://api.giphy.com/v1/gifs/trending?api_key="..api_key) + local images = json:decode(b).data + math.randomseed(os.time()) + local i = math.random(0,#images) + return images[i].images.downsized.url +end + +function search(text) + local api_key = "dc6zaTOxFJmzC" -- public beta key + b = http.request("http://api.giphy.com/v1/gifs/search?q="..text.."&api_key="..api_key) + local images = json:decode(b).data + math.randomseed(os.time()) + local i = math.random(0,#images) + return images[i].images.downsized.url +end + +function run(msg, matches) + -- If no search data, a cat gif will be sended + -- Because everyone loves pussies + if matches[1] == "!gif" or matches[1] == "!giphy" then + gif_url = get_random_top() + else + gif_url = search(matches[1]) + end + + file = download_to_file(gif_url) + send_document(get_receiver(msg), file, ok_cb, false) + return "preparing to make you laugh" +end + +return { + description = "Sends you a laughable gif", + usage = "", + patterns = { + "^!gif$", + "^!gif (.*)", + "^!giphy (.*)", + "^!giphy$" + }, + run = run +} \ No newline at end of file From d9d96ed81ca798a8c577bb2d8d614e030893b7b7 Mon Sep 17 00:00:00 2001 From: Yago Date: Wed, 14 Jan 2015 15:52:30 +0100 Subject: [PATCH 04/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 162a156..9e90998 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ If your linux/unix comes with [upstart](http://upstart.ubuntu.com/) you can run $ sed -i "s/yourusername/$(whoami)/g" etc/telegram.conf $ sed -i "s_telegrambotpath_$(pwd)_g" etc/telegram.conf $ sudo cp etc/telegram.conf /etc/init/ +$ sudo start telegram # To start it +$ sudo stop telegram # To stop it ``` Contact me From a35bddc076b2bdc0a8a3b5dc1445c71e348c8b5c Mon Sep 17 00:00:00 2001 From: yago Date: Fri, 23 Jan 2015 23:49:51 +0100 Subject: [PATCH 05/10] Help table generator --- plugins/9gag.lua | 4 +-- plugins/giphy.lua | 7 ++++-- plugins/google.lua | 4 +-- plugins/help.lua | 61 ++++++++++++++++++++++++++++++++++++++++----- plugins/invite.lua | 4 ++- plugins/plugins.lua | 11 +++++--- 6 files changed, 74 insertions(+), 17 deletions(-) diff --git a/plugins/9gag.lua b/plugins/9gag.lua index a40354f..0d4a4f3 100644 --- a/plugins/9gag.lua +++ b/plugins/9gag.lua @@ -27,8 +27,8 @@ function run(msg, matches) end return { - description = "send random image from 9gag", - usage = "!9gag", + description = "9GAG for telegram", + usage = "!9gag: Send random image from 9gag", patterns = {"^!9gag$"}, run = run } diff --git a/plugins/giphy.lua b/plugins/giphy.lua index ccf8697..a2a4ea1 100644 --- a/plugins/giphy.lua +++ b/plugins/giphy.lua @@ -34,8 +34,11 @@ function run(msg, matches) end return { - description = "Sends you a laughable gif", - usage = "", + description = "GIFs from telegram with Giphy API", + usage = { + "!gif (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.", + "!giphy (term): Search and sends GIF from Giphy. If no param, sends a trending GIF." + }, patterns = { "^!gif$", "^!gif (.*)", diff --git a/plugins/google.lua b/plugins/google.lua index d3b22de..0481962 100644 --- a/plugins/google.lua +++ b/plugins/google.lua @@ -28,8 +28,8 @@ function run(msg, matches) end return { - description = "Searches Google", - usage = "!google terms", + description = "Searches Google and send results", + usage = "!google [terms]", patterns = { "^!google (.*)$", "^%.[g|G]oogle (.*)$" diff --git a/plugins/help.lua b/plugins/help.lua index d02e43a..31b29e8 100644 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -1,17 +1,66 @@ +-- Generate an HTML table for GitHub +function html_help() + local text = [[ + + + + + + + + ]] -function run(msg, matches) + for k,v in pairs(plugins_names()) do + t = loadfile("plugins/"..v)() + text = text.."" + text = text.."" + text = text.."" + text = text.."" + text = text.."" + end + text = text.."
NameDescriptionUsage
"..v..""..t.description.."" + if (type(t.usage) == "table") then + for ku,vu in pairs(t.usage) do + text = text..vu.."
" + end + else + text = text..t.usage + end + text = text.."
" + return text +end + +function telegram_help( ) local ret = "" for k, dict in pairs(plugins) do - if dict.usage ~= "" then - ret = ret .. dict.usage .. " -> " .. dict.description .. "\n" - end + if dict.usage ~= "" then + if (type(dict.usage) == "table") then + for ku,vu in pairs(dict.usage) do + ret = ret..vu.." " + end + else + ret = ret..dict.usage + end + ret = ret .. " -> " .. dict.description .. "\n" + end end return ret end +function run(msg, matches) + if matches[1] == "!help md" then + return html_help() + else + return telegram_help() + end +end + return { description = "Lists all available commands", - usage = "!help", - patterns = {"^!help$"}, + usage = {"!help", "!help md"}, + patterns = { + "^!help$", + "^!help md$" + }, run = run } \ No newline at end of file diff --git a/plugins/invite.lua b/plugins/invite.lua index b47e848..cd5f452 100644 --- a/plugins/invite.lua +++ b/plugins/invite.lua @@ -31,7 +31,9 @@ end return { description = "Invite other user to the chat group", - usage = "!invite name [user_name], !invite id [user_id]", + usage = { + "!invite name [user_name]", + "!invite id [user_id]" }, patterns = { "^!invite (name) (.*)$", "^!invite (id) (%d+)$" diff --git a/plugins/plugins.lua b/plugins/plugins.lua index af729a7..323b6c6 100644 --- a/plugins/plugins.lua +++ b/plugins/plugins.lua @@ -100,14 +100,17 @@ function run(msg, matches) end return { - description = "Enables, disables and reloads plugins", - usage = "!plugins, !plugins enable [plugin], !plugins disable [plugin], !plugins reload", + description = "Enables, disables and reloads plugins. Privileged users only.", + usage = { + "!plugins: list all plugins", + "!plugins enable [plugin]", + "!plugins disable [plugin]", + "!plugins reload" }, patterns = { "^!plugins$", "^!plugins? (enable) (.*)$", "^!plugins? (disable) (.*)$", - "^!plugins? (reload)$" - }, + "^!plugins? (reload)$" }, run = run, privileged = true } \ No newline at end of file From 700f9e395e9b68359427a9cb427a1dbedef909d0 Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 24 Jan 2015 16:54:59 +0100 Subject: [PATCH 06/10] Enable more plugins by default --- bot/bot.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/bot.lua b/bot/bot.lua index cb9dd85..a7d2f99 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -145,6 +145,8 @@ function create_config( ) "9gag", "echo", "get", + "giphy", + "google", "help", "images", "img_google", @@ -155,6 +157,7 @@ function create_config( ) "stats", "time", "version", + "weather", "youtube" }, sudo_users = {our_id} } From f6e6db50c02c000164624d5a21a9e921f0fb70e7 Mon Sep 17 00:00:00 2001 From: Yago Date: Sat, 24 Jan 2015 17:16:35 +0100 Subject: [PATCH 07/10] Update README.md --- README.md | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9e90998..e363625 100644 --- a/README.md +++ b/README.md @@ -12,21 +12,17 @@ Multimedia ![http://i.imgur.com/0FGUvU0.png](http://i.imgur.com/0FGUvU0.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/zW7WWWt.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/kPK7paz.png) -Default enabled commands +Bot Commands ------------ -``` -!9gag -> send random image from 9gag -!echo [whatever] -> echoes the msg -!get (value_name) -> retrieves variables saved with !set -!set [value_name] [data] -> Set value -!img [topic] -> search image with Google API and sends it -!loc (location) -> Gets information about a location, maplink and overview -!stats -> Numer of messages by user -!time [area] -> Displays the local time in an area -!version -> Shows bot version -!google terms -> Searches Google -!help -> Lists all available commands -``` + + + + + + + + +
NameDescriptionUsage
9gag.lua9GAG for telegram!9gag: Send random image from 9gag
btc.luaBitcoin global average market value (in EUR or USD)!btc [EUR|USD] [amount]
echo.luaechoes the msg!echo [whatever]
eur.luaEURUSD market value!eur [USD]
fortunes_uc3m.luaFortunes from Universidad Carlos III!uc3m
get.luaretrieves variables saved with !set!get (value_name)
giphy.luaGIFs from telegram with Giphy API!gif (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.
!giphy (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.
google.luaSearches Google and send results!google [terms]
gps.luagenerates a map showing the given GPS coordinates!gps latitude,longitude
hello.luaSays hello to someonesay hello to [name]
help.luaLists all available commands!help
!help md
images.luaWhen user sends image URL (ends with png, jpg, jpeg) download and send it to origin.
img_google.luasearch image with Google API and sends it!img [topic]
invite.luaInvite other user to the chat group!invite name [user_name]
!invite id [user_id]
location.luaGets information about a location, maplink and overview!loc (location)
media.luaWhen user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.
ping.luaIf domain is offline, send msg to peer
plugins.luaEnables, disables and reloads plugins. Privileged users only.!plugins: list all plugins
!plugins enable [plugin]
!plugins disable [plugin]
!plugins reload
rae.luaSpanish dictionary!rae [word]
set.luaSet value!set [value_name] [data]
stats.luaNumer of messages by user!stats
time.luaDisplays the local time in an area!time [area]
twitter.luaWhen user sends twitter URL, send text and images to origin. Requieres OAuth Key.
twitter_send.luaSends a tweet!tw [text]
version.luaShows bot version!version
weather.luaweather in that city (Madrid is default)!weather (city)
youtube.luasends YouTube image
Installation ------------ From 5b0cbc807277e4349122d31df4b5c4255083d2ce Mon Sep 17 00:00:00 2001 From: Yago Date: Sat, 24 Jan 2015 17:18:13 +0100 Subject: [PATCH 08/10] Update version --- bot/bot.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index a7d2f99..8dd97bd 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -5,7 +5,7 @@ json = (loadfile "./libs/JSON.lua")() serpent = (loadfile "./libs/serpent.lua")() require("./bot/utils") -VERSION = '0.8.3' +VERSION = '0.8.4' function on_msg_receive (msg) vardump(msg) @@ -209,4 +209,4 @@ end -- Start and load values our_id = 0 -now = os.time() \ No newline at end of file +now = os.time() From f743a706afb8973ff5b77f9b89efc91ccb1785b2 Mon Sep 17 00:00:00 2001 From: Claudio Filho Date: Mon, 2 Feb 2015 14:57:41 -0200 Subject: [PATCH 09/10] Fixing stats to show the result sorted by messages --- plugins/stats.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/stats.lua b/plugins/stats.lua index e9fcf7e..131f94c 100644 --- a/plugins/stats.lua +++ b/plugins/stats.lua @@ -61,12 +61,23 @@ local function get_stats_status( msg ) -- vardump(stats) local text = "" local to_id = tostring(msg.to.id) + local rank = {} for id, user in pairs(_stats[to_id]) do + table.insert(rank, user) + end + table.sort(rank, function(a, b) + if a.msg_num and b.msg_num then + return a.msg_num > b.msg_num + end + end + ) + for id, user in pairs(rank) do + print(">> ", id, user.name) if user.last_name == nil then - text = text..user.name.." ["..id.."]: "..user.msg_num.."\n" + text = text..user.name..": "..user.msg_num.."\n" else - text = text..user.name.." "..user.last_name.." ["..id.."]: "..user.msg_num.."\n" + text = text..user.name.." "..user.last_name..": "..user.msg_num.."\n" end end print("usuarios: "..text) @@ -75,7 +86,7 @@ end local function run(msg, matches) if matches[1] == "stats" then -- Hack - return get_stats_status(msg) + return get_stats_status(msg) else print ("update stats") update_user_stats(msg) @@ -86,7 +97,7 @@ end _stats = read_file_stats() return { - description = "Numer of messages by user", + description = "Number of messages by user", usage = "!stats", patterns = { ".*", @@ -95,4 +106,4 @@ return { run = run } -end \ No newline at end of file +end From 88e094913c8329582f9645775df20c6ecdb7f09f Mon Sep 17 00:00:00 2001 From: PotHix Date: Mon, 2 Feb 2015 15:59:26 -0200 Subject: [PATCH 10/10] Fixes typo on 'eanbled' --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e363625..289f957 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ Installation $ 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 +$ tar -xzvf luarocks-2.2.0.tar.gz $ cd luarocks-2.2.0/ -$ ./configure +$ ./configure $ make && sudo make install $ sudo luarocks install oauth $ sudo luarocks install luasocket @@ -53,7 +53,7 @@ See the plugins list with `!plugins` command. Enable a disabled plugin by `!plugins enable [name]`. -Disable an eanbled plugin by `!plugins disable [name]`. +Disable an enabled plugin by `!plugins disable [name]`. Those commands require a privileged user, privileged users are defined inside `data/config.lua` (generated by the bot), stop de bot and edit if necessary.