Merge branch 'develop'

This commit is contained in:
yago 2015-02-04 23:05:06 +01:00
commit 1ffd231ed5
19 changed files with 152 additions and 67 deletions

View File

@ -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
```
<table>
<thead>
<tr>
<td><strong>Name</strong></td>
<td><strong>Description</strong></td>
<td><strong>Usage</strong></td>
</tr>
</thead>
<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>
Installation
------------
@ -57,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.

View File

@ -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)

View File

@ -31,14 +31,18 @@ function string:split(sep)
return fields
end
-- Removes spaces
function string.trim(s)
return s:gsub("^%s*(.-)%s*$", "%1")
end
function download_to_file( url , noremove )
print("url to download: "..url)
local ltn12 = require "ltn12"
local respbody = {}
one, c, h = http.request{url=url, sink=ltn12.sink.table(respbody), redirect=true}
htype = h["content-type"]
vardump(c)
print("content-type: "..htype)
if htype == "image/jpeg" then
file_name = string.random(5)..".jpg"
file_path = "/tmp/"..file_name
@ -186,3 +190,8 @@ end
function string:isempty()
return self == nil or self == ''
end
function string.starts(String, Start)
return Start == string.sub(String,1,string.len(Start))
end

View File

@ -4,8 +4,8 @@ function run(msg, matches)
end
return {
description = "echoes the msg",
usage = "!echo [whatever]",
description = "Simplest plugin ever!",
usage = "!echo [whatever]: echoes the msg",
patterns = {"^!echo (.*)$"},
run = run
}

View File

@ -72,8 +72,8 @@ function lex(msg, text)
end
return {
description = "retrieves variables saved with !set",
usage = "!get (value_name)",
description = "Retrieves variables saved with !set",
usage = "!get (value_name): Returns the value_name value.",
patterns = {
"^!get (%a+)$",
"^!get$"},

View File

@ -29,7 +29,7 @@ end
return {
description = "Searches Google and send results",
usage = "!google [terms]",
usage = "!google [terms]: Searches Google and send results",
patterns = {
"^!google (.*)$",
"^%.[g|G]oogle (.*)$"

View File

@ -25,7 +25,7 @@ end
return {
description = "generates a map showing the given GPS coordinates",
usage = "!gps latitude,longitude",
usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates",
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
run = run
}

View File

@ -30,18 +30,23 @@ function html_help()
return text
end
function has_usage_data(dict)
if (dict.usage == nil or dict.usage == '') then
return false
end
return true
end
function telegram_help( )
local ret = ""
for k, dict in pairs(plugins) do
if dict.usage ~= "" then
if (type(dict.usage) == "table") then
for ku,vu in pairs(dict.usage) do
ret = ret..vu.." "
for ku,usage in pairs(dict.usage) do
ret = ret..usage..'\n'
end
else
ret = ret..dict.usage
end
ret = ret .. " -> " .. dict.description .. "\n"
ret = ret..'\n'
elseif has_usage_data(dict) then -- Is not empty
ret = ret..dict.usage..'\n\n'
end
end
return ret
@ -56,8 +61,11 @@ function run(msg, matches)
end
return {
description = "Lists all available commands",
usage = {"!help", "!help md"},
description = "Help plugin. Get info from other plugins. ",
usage = {
"!help: Show all the help",
"!help md: Generate a GitHub Markdown table"
},
patterns = {
"^!help$",
"^!help md$"

View File

@ -25,8 +25,8 @@ function run(msg, matches)
end
return {
description = "search image with Google API and sends it",
usage = "!img [topic]",
description = "Search image with Google API and sends it.",
usage = "!img [term]: Random search an image with Google API.",
patterns = {"^!img (.*)$"},
run = run
}

View File

@ -64,7 +64,7 @@ end
return {
description = "Gets information about a location, maplink and overview",
usage = "!loc (location)",
usage = "!loc (location): Gets information about a location, maplink and overview",
patterns = {"^!loc (.*)$"},
run = run
}

View File

@ -100,12 +100,12 @@ function run(msg, matches)
end
return {
description = "Enables, disables and reloads plugins. Privileged users only.",
description = "Plugin to manage other plugins. Enable, disable or reload.",
usage = {
"!plugins: list all plugins",
"!plugins enable [plugin]",
"!plugins disable [plugin]",
"!plugins reload" },
"!plugins enable [plugin]: enable plugin",
"!plugins disable [plugin]: disable plugin",
"!plugins reload: reloads all plugins" },
patterns = {
"^!plugins$",
"^!plugins? (enable) (.*)$",

View File

@ -41,7 +41,7 @@ end
return {
description = "Spanish dictionary",
usage = "!rae [word]",
usage = "!rae [word]: Search that word in Spanish dictionary. Powered by https://github.com/javierhonduco/dulcinea",
patterns = {"^!rae (.*)$"},
run = run
}

View File

@ -23,8 +23,8 @@ function run(msg, matches)
end
return {
description = "Set value",
usage = "!set [value_name] [data]",
description = "Plugin for saving values. get.lua plugin is necesary to retrieve them.",
usage = "!set [value_name] [data]: Saves the data with the value_name name.",
patterns = {"^!set (%a+) (.+)$"},
run = run
}

View File

@ -23,6 +23,7 @@ function update_user_stats(msg)
if _stats[to_id][from_id] == nil then
print ('New stats key from_id: '..to_id)
_stats[to_id][from_id] = {
user_id = from_id,
name = user_name,
last_name = user_last_name,
print_name = user_print_name,
@ -32,7 +33,7 @@ function update_user_stats(msg)
print ('Updated '..to_id..' '..from_id)
local actual_num = _stats[to_id][from_id].msg_num
_stats[to_id][from_id].msg_num = actual_num + 1
-- And update last_name
_stats[to_id][from_id].user_id = from_id
_stats[to_id][from_id].last_name = user_last_name
end
end
@ -61,12 +62,27 @@ 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
-- Previous versions didn't save that
user_id = user.user_id or ''
print(">> ", id, user.name)
if user.last_name == nil then
text = text..user.name.." ["..id.."]: "..user.msg_num.."\n"
text = text..user.name.." ["..user_id.."]: "..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_id.."]: "..user.msg_num.."\n"
end
end
print("usuarios: "..text)
@ -86,8 +102,8 @@ end
_stats = read_file_stats()
return {
description = "Numer of messages by user",
usage = "!stats",
description = "Plugin to update user stats.",
usage = "!stats: Returns a list of Username [telegram_id]: msg_num",
patterns = {
".*",
"^!(stats)"

View File

@ -94,7 +94,7 @@ end
return {
description = "Displays the local time in an area",
usage = "!time [area]",
usage = "!time [area]: Displays the local time in that area",
patterns = {"^!time (.*)$"},
run = run
}

View File

@ -16,16 +16,16 @@ local client = OAuth.new(consumer_key, consumer_secret, {
function run(msg, matches)
if consumer_key:isempty() then
return "Twitter Consumer Key is empty, write it in plugins/twitter.lua"
return "Twitter Consumer Key is empty, write it in plugins/twitter_send.lua"
end
if consumer_secret:isempty() then
return "Twitter Consumer Secret is empty, write it in plugins/twitter.lua"
return "Twitter Consumer Secret is empty, write it in plugins/twitter_send.lua"
end
if access_token:isempty() then
return "Twitter Access Token is empty, write it in plugins/twitter.lua"
return "Twitter Access Token is empty, write it in plugins/twitter_send.lua"
end
if access_token_secret:isempty() then
return "Twitter Access Token Secret is empty, write it in plugins/twitter.lua"
return "Twitter Access Token Secret is empty, write it in plugins/twitter_send.lua"
end
if not is_sudo(msg) then
@ -44,7 +44,7 @@ end
return {
description = "Sends a tweet",
usage = "!tw [text]",
usage = "!tw [text]: Sends the Tweet with the configured accout.",
patterns = {"^!tw (.+)"},
run = run
}

View File

@ -7,8 +7,10 @@ end
return {
description = "Shows bot version",
usage = "!version",
patterns = {"^!version$"},
usage = "!version: Shows bot version",
patterns = {
"^!version$"
},
run = run
}

54
plugins/xkcd.lua Normal file
View File

@ -0,0 +1,54 @@
function get_last_id()
local res,code = https.request("http://xkcd.com/info.0.json")
if code ~= 200 then return "HTTP ERROR" end
local data = json:decode(res)
return data.num
end
function get_xkcd(id)
local res,code = http.request("http://xkcd.com/"..id.."/info.0.json")
if code ~= 200 then return "HTTP ERROR" end
local data = json:decode(res)
local link_image = data.img
if link_image:sub(0,2) == '//' then
link_image = msg.text:sub(3,-1)
end
return link_image, data.title
end
function get_xkcd_random()
local last = get_last_id()
math.randomseed(os.time())
i = math.random(1, data.num)
return get_xkcd(i)
end
function send_title(cb_extra, success, result)
if success then
send_msg(cb_extra[1], cb_extra[2], ok_cb, false)
end
end
function run(msg, matches)
local receiver = get_receiver(msg)
if matches[1] == "!xkcd" then
url, title = get_xkcd_random()
else
url, title = get_xkcd(matches[1])
end
file_path = download_to_file(url)
send_photo(receiver, file_path, send_title, {receiver, title})
return false
end
return {
description = "Send comic images from xkcd",
usage = {"!xkcd (id): Send an xkcd image and tigle. If not id, send a random one"},
patterns = {
"^!xkcd$",
"^!xkcd (%d+)",
"xkcd.com/(%d+)"
},
run = run
}

2
tg

@ -1 +1 @@
Subproject commit d74db187ef3ed9a152979274ba2ea2ad8fe8c8d3
Subproject commit 01f5d9a3b671edc15a5cff285601115845489985