Merge branch 'but3k4-master' into develop

This commit is contained in:
yago 2015-02-02 22:44:24 +01:00
commit 792209c607
3 changed files with 52 additions and 32 deletions

View File

@ -11,38 +11,29 @@ Multimedia
- When user sends youtube URL, send to origin video image. - 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) ![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
------------ ------------
``` <table>
!9gag -> send random image from 9gag <thead>
!echo [whatever] -> echoes the msg <tr>
!eur [USD] -> EURUSD market value <td><strong>Name</strong></td>
!uc3m -> Fortunes from Universidad Carlos III <td><strong>Description</strong></td>
!get (value_name) -> retrieves variables saved with !set <td><strong>Usage</strong></td>
say hello to [name] -> Says hello to someone </tr>
!help -> Lists all available commands </thead>
!img [topic] -> search image with Google API and sends it <tbody><tr><td>9gag.lua</td><td>9GAG for telegram</td><td>!9gag: Send random image from 9gag</td></tr><tr><td>btc.lua</td><td>Bitcoin global average market value (in EUR or USD)</td><td>!btc [EUR|USD] [amount]</td></tr><tr><td>echo.lua</td><td>echoes the msg</td><td>!echo [whatever]</td></tr><tr><td>eur.lua</td><td>EURUSD market value</td><td>!eur [USD]</td></tr><tr><td>fortunes_uc3m.lua</td><td>Fortunes from Universidad Carlos III</td><td>!uc3m</td></tr><tr><td>get.lua</td><td>retrieves variables saved with !set</td><td>!get (value_name)</td></tr><tr><td>giphy.lua</td><td>GIFs from telegram with Giphy API</td><td>!gif (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.<br>!giphy (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.<br></td></tr><tr><td>google.lua</td><td>Searches Google and send results</td><td>!google [terms]</td></tr><tr><td>gps.lua</td><td>generates a map showing the given GPS coordinates</td><td>!gps latitude,longitude</td></tr><tr><td>hello.lua</td><td>Says hello to someone</td><td>say hello to [name]</td></tr><tr><td>help.lua</td><td>Lists all available commands</td><td>!help<br>!help md<br></td></tr><tr><td>images.lua</td><td>When user sends image URL (ends with png, jpg, jpeg) download and send it to origin.</td><td></td></tr><tr><td>img_google.lua</td><td>search image with Google API and sends it</td><td>!img [topic]</td></tr><tr><td>invite.lua</td><td>Invite other user to the chat group</td><td>!invite name [user_name]<br>!invite id [user_id]<br></td></tr><tr><td>location.lua</td><td>Gets information about a location, maplink and overview</td><td>!loc (location)</td></tr><tr><td>media.lua</td><td>When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.</td><td></td></tr><tr><td>ping.lua</td><td>If domain is offline, send msg to peer</td><td></td></tr><tr><td>plugins.lua</td><td>Enables, disables and reloads plugins. Privileged users only.</td><td>!plugins: list all plugins<br>!plugins enable [plugin]<br>!plugins disable [plugin]<br>!plugins reload<br></td></tr><tr><td>rae.lua</td><td>Spanish dictionary</td><td>!rae [word]</td></tr><tr><td>set.lua</td><td>Set value</td><td>!set [value_name] [data]</td></tr><tr><td>stats.lua</td><td>Numer of messages by user</td><td>!stats</td></tr><tr><td>time.lua</td><td>Displays the local time in an area</td><td>!time [area]</td></tr><tr><td>twitter.lua</td><td>When user sends twitter URL, send text and images to origin. Requieres OAuth Key.</td><td></td></tr><tr><td>twitter_send.lua</td><td>Sends a tweet</td><td>!tw [text]</td></tr><tr><td>version.lua</td><td>Shows bot version</td><td>!version</td></tr><tr><td>weather.lua</td><td>weather in that city (Madrid is default)</td><td>!weather (city)</td></tr><tr><td>youtube.lua</td><td>sends YouTube image</td><td></td></tr></tbody></table>
!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)
```
Installation Installation
------------ ------------
```bash ```bash
# Tested on Ubuntu 14.04, for other OSs check out https://github.com/vysheng/tg#installation # 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 $ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev unzip git
$ cd /tmp $ cd /tmp
$ wget http://luarocks.org/releases/luarocks-2.2.0.tar.gz $ 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/ $ cd luarocks-2.2.0/
$ ./configure $ ./configure
$ make && sudo make install $ make && sudo make install
$ sudo luarocks install oauth $ sudo luarocks install oauth
$ sudo luarocks install luasocket $ sudo luarocks install luasocket
@ -52,12 +43,30 @@ $ sudo luarocks install luasocket
$ cd $HOME $ cd $HOME
$ git clone https://github.com/yagop/telegram-bot.git --recursive $ git clone https://github.com/yagop/telegram-bot.git --recursive
$ cd telegram-bot/tg $ cd telegram-bot/tg
$ ./configure && make $ ./configure && make && cd ..
$ 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/yourusername/$(whoami)/g" etc/telegram.conf
$ sed -i "s_telegrambotpath_$(pwd)_g" etc/telegram.conf $ sed -i "s_telegrambotpath_$(pwd)_g" etc/telegram.conf
$ sudo cp etc/telegram.conf /etc/init/ $ 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 Contact me

View File

@ -5,7 +5,7 @@ json = (loadfile "./libs/JSON.lua")()
serpent = (loadfile "./libs/serpent.lua")() serpent = (loadfile "./libs/serpent.lua")()
require("./bot/utils") require("./bot/utils")
VERSION = '0.8.3' VERSION = '0.8.4'
function on_msg_receive (msg) function on_msg_receive (msg)
vardump(msg) vardump(msg)
@ -209,4 +209,4 @@ end
-- Start and load values -- Start and load values
our_id = 0 our_id = 0
now = os.time() now = os.time()

View File

@ -61,12 +61,23 @@ local function get_stats_status( msg )
-- vardump(stats) -- vardump(stats)
local text = "" local text = ""
local to_id = tostring(msg.to.id) local to_id = tostring(msg.to.id)
local rank = {}
for id, user in pairs(_stats[to_id]) do 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 if user.last_name == nil then
text = text..user.name.." ["..id.."]: "..user.msg_num.."\n" text = text..user.name..": "..user.msg_num.."\n"
else 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
end end
print("usuarios: "..text) print("usuarios: "..text)
@ -75,7 +86,7 @@ end
local function run(msg, matches) local function run(msg, matches)
if matches[1] == "stats" then -- Hack if matches[1] == "stats" then -- Hack
return get_stats_status(msg) return get_stats_status(msg)
else else
print ("update stats") print ("update stats")
update_user_stats(msg) update_user_stats(msg)
@ -86,7 +97,7 @@ end
_stats = read_file_stats() _stats = read_file_stats()
return { return {
description = "Numer of messages by user", description = "Number of messages by user",
usage = "!stats", usage = "!stats",
patterns = { patterns = {
".*", ".*",
@ -95,4 +106,4 @@ return {
run = run run = run
} }
end end