diff --git a/README.md b/README.md index 077b642..289f957 100644 --- a/README.md +++ b/README.md @@ -11,38 +11,29 @@ 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 + +Bot 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 -!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) -``` + + + + + + + + +
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 ------------ - ```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 $ 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 @@ -52,12 +43,30 @@ $ 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 a disabled plugin by `!plugins enable [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. + + +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. +$ sudo start telegram # To start it +$ sudo stop telegram # To stop it ``` Contact me 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() 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