Some code clean up

This commit is contained in:
yago 2014-11-22 15:05:54 +01:00
parent 8698082b3a
commit e11b393643
7 changed files with 18 additions and 36 deletions

View File

@ -35,7 +35,7 @@ Multimedia
Command list Command list
------------ ------------
``` ```
9gag -> send random image from 9gag !9gag -> send random image from 9gag
!echo [whatever] -> echoes the msg !echo [whatever] -> echoes the msg
!eur [USD] -> EURUSD market value !eur [USD] -> EURUSD market value
!uc3m -> Fortunes from Universidad Carlos III !uc3m -> Fortunes from Universidad Carlos III
@ -46,8 +46,9 @@ say hello to [name] -> Says hello to someone
!ping -> bot sends pong !ping -> bot sends pong
!rae [word] -> Spanish dictionary !rae [word] -> Spanish dictionary
!set [value_name] [data] -> Set value !set [value_name] [data] -> Set value
!time [area] -> Displays the local time in an area
!tw [text] -> Sends a tweet !tw [text] -> Sends a tweet
!version -> Shows the bot version !version -> Shows bot version
!weather (city) -> weather in that city (Madrid is default) !weather (city) -> weather in that city (Madrid is default)
``` ```

View File

@ -2,9 +2,8 @@
https = require("ssl.https") https = require("ssl.https")
URL = require("socket.url") URL = require("socket.url")
json = (loadfile "./bot/JSON.lua")() json = (loadfile "./bot/JSON.lua")()
-- lrexlib = require("rex_pcre")
VERSION = 'v0.6' VERSION = 'v0.7'
-- taken from http://stackoverflow.com/a/11130774/3163199 -- taken from http://stackoverflow.com/a/11130774/3163199
function scandir(directory) function scandir(directory)
@ -55,16 +54,16 @@
function do_action(msg) function do_action(msg)
local receiver = get_receiver(msg) local receiver = get_receiver(msg)
local text = msg.text local text = msg.text
print("Received msg", text) -- print("Received msg", text)
for name, desc in pairs(plugins) do for name, desc in pairs(plugins) do
print("Trying module", name) -- print("Trying module", name)
for k, pattern in pairs(desc.patterns) do for k, pattern in pairs(desc.patterns) do
print("Trying", text, "against", pattern) -- print("Trying", text, "against", pattern)
matches = { string.match(text, pattern) } matches = { string.match(text, pattern) }
if matches[1] then if matches[1] then
print(" matches!") print(" matches!!!!!")
result = desc.run(msg, matches) result = desc.run(msg, matches)
print(" should return", result) print(" sending", result)
if (result) then if (result) then
send_msg(receiver, result, ok_cb, false) send_msg(receiver, result, ok_cb, false)
return return
@ -74,25 +73,6 @@
end end
end end
-- function do_action(msg)
-- local receiver = get_receiver(msg)
-- if string.starts(msg.text, '!sh') then
-- text = run_sh(msg)
-- send_msg(receiver, text, ok_cb, false)
-- return
-- end
--
-- if string.starts(msg.text, '!cpu') then
-- text = run_bash('uname -snr') .. ' ' .. run_bash('whoami')
-- text = text .. '\n' .. run_bash('top -b |head -2')
-- send_msg(receiver, text, ok_cb, false)
-- return
-- end
-- end
function load_config() function load_config()
local f = assert(io.open('./bot/config.json', "r")) local f = assert(io.open('./bot/config.json', "r"))
local c = f:read "*a" local c = f:read "*a"
@ -166,7 +146,7 @@
end end
function download_to_file( url ) function download_to_file( url )
print("url a descargar: "..url) print("url to download: "..url)
req, c, h = http.request(url) req, c, h = http.request(url)
htype = h["content-type"] htype = h["content-type"]
vardump(c) vardump(c)

View File

@ -2,7 +2,9 @@
function run(msg, matches) function run(msg, matches)
local ret = "" local ret = ""
for k, dict in pairs(plugins) do for k, dict in pairs(plugins) do
ret = ret .. dict.usage .. " -> " .. dict.description .. "\n" if dict.usage ~= "" then
ret = ret .. dict.usage .. " -> " .. dict.description .. "\n"
end
end end
return ret return ret
end end
@ -12,5 +14,4 @@ return {
usage = "!help", usage = "!help",
patterns = {"^!help$"}, patterns = {"^!help$"},
run = run run = run
} }

View File

@ -6,7 +6,7 @@ function run(msg, matches)
end end
return { return {
description = "from image URL downloads it and sends to origin", description = "When user sends image URL (ends with png, jpg, jpeg) download and send it to origin.",
usage = "", usage = "",
patterns = { patterns = {
"(https?://[%w-_%.%?%.:/%+=&]+.png)$", "(https?://[%w-_%.%?%.:/%+=&]+.png)$",

View File

@ -5,7 +5,7 @@ function run(msg, matches)
end end
return { return {
description = "from media URL downloads it and sends to origin", description = "When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.",
usage = "", usage = "",
patterns = { patterns = {
"(https?://[%w-_%.%?%.:/%+=&]+.gif)$", "(https?://[%w-_%.%?%.:/%+=&]+.gif)$",

View File

@ -61,7 +61,7 @@ function run(msg, matches)
end end
return { return {
description = "Shows a tweet", description = "When user sends twitter URL, send text and images to origin. Requieres OAuth Key.",
usage = "", usage = "",
patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"}, patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"},
run = run run = run

View File

@ -8,7 +8,7 @@ function run(msg, matches)
end end
return { return {
description = "Shows the bot version", description = "Shows bot version",
usage = "!version", usage = "!version",
patterns = {"^!version$"}, patterns = {"^!version$"},
run = run run = run