Some code clean up
This commit is contained in:
parent
8698082b3a
commit
e11b393643
@ -35,7 +35,7 @@ Multimedia
|
||||
Command list
|
||||
------------
|
||||
```
|
||||
9gag -> send random image from 9gag
|
||||
!9gag -> send random image from 9gag
|
||||
!echo [whatever] -> echoes the msg
|
||||
!eur [USD] -> EURUSD market value
|
||||
!uc3m -> Fortunes from Universidad Carlos III
|
||||
@ -46,8 +46,9 @@ say hello to [name] -> Says hello to someone
|
||||
!ping -> bot sends pong
|
||||
!rae [word] -> Spanish dictionary
|
||||
!set [value_name] [data] -> Set value
|
||||
!time [area] -> Displays the local time in an area
|
||||
!tw [text] -> Sends a tweet
|
||||
!version -> Shows the bot version
|
||||
!version -> Shows bot version
|
||||
!weather (city) -> weather in that city (Madrid is default)
|
||||
```
|
||||
|
||||
|
34
bot/bot.lua
34
bot/bot.lua
@ -2,9 +2,8 @@
|
||||
https = require("ssl.https")
|
||||
URL = require("socket.url")
|
||||
json = (loadfile "./bot/JSON.lua")()
|
||||
-- lrexlib = require("rex_pcre")
|
||||
|
||||
VERSION = 'v0.6'
|
||||
VERSION = 'v0.7'
|
||||
|
||||
-- taken from http://stackoverflow.com/a/11130774/3163199
|
||||
function scandir(directory)
|
||||
@ -55,16 +54,16 @@
|
||||
function do_action(msg)
|
||||
local receiver = get_receiver(msg)
|
||||
local text = msg.text
|
||||
print("Received msg", text)
|
||||
-- print("Received msg", text)
|
||||
for name, desc in pairs(plugins) do
|
||||
print("Trying module", name)
|
||||
-- print("Trying module", name)
|
||||
for k, pattern in pairs(desc.patterns) do
|
||||
print("Trying", text, "against", pattern)
|
||||
-- print("Trying", text, "against", pattern)
|
||||
matches = { string.match(text, pattern) }
|
||||
if matches[1] then
|
||||
print(" matches!")
|
||||
print(" matches!!!!!")
|
||||
result = desc.run(msg, matches)
|
||||
print(" should return", result)
|
||||
print(" sending", result)
|
||||
if (result) then
|
||||
send_msg(receiver, result, ok_cb, false)
|
||||
return
|
||||
@ -74,25 +73,6 @@
|
||||
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()
|
||||
local f = assert(io.open('./bot/config.json', "r"))
|
||||
local c = f:read "*a"
|
||||
@ -166,7 +146,7 @@
|
||||
end
|
||||
|
||||
function download_to_file( url )
|
||||
print("url a descargar: "..url)
|
||||
print("url to download: "..url)
|
||||
req, c, h = http.request(url)
|
||||
htype = h["content-type"]
|
||||
vardump(c)
|
||||
|
@ -2,7 +2,9 @@
|
||||
function run(msg, matches)
|
||||
local ret = ""
|
||||
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
|
||||
return ret
|
||||
end
|
||||
@ -13,4 +15,3 @@ return {
|
||||
patterns = {"^!help$"},
|
||||
run = run
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ function run(msg, matches)
|
||||
end
|
||||
|
||||
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 = "",
|
||||
patterns = {
|
||||
"(https?://[%w-_%.%?%.:/%+=&]+.png)$",
|
||||
|
@ -5,7 +5,7 @@ function run(msg, matches)
|
||||
end
|
||||
|
||||
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 = "",
|
||||
patterns = {
|
||||
"(https?://[%w-_%.%?%.:/%+=&]+.gif)$",
|
||||
|
@ -61,7 +61,7 @@ function run(msg, matches)
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Shows a tweet",
|
||||
description = "When user sends twitter URL, send text and images to origin. Requieres OAuth Key.",
|
||||
usage = "",
|
||||
patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"},
|
||||
run = run
|
||||
|
@ -8,7 +8,7 @@ function run(msg, matches)
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Shows the bot version",
|
||||
description = "Shows bot version",
|
||||
usage = "!version",
|
||||
patterns = {"^!version$"},
|
||||
run = run
|
||||
|
Reference in New Issue
Block a user