multiple patterns
This commit is contained in:
parent
6ef55411a1
commit
7d8abde1d1
18
bot/bot.lua
18
bot/bot.lua
@ -1,7 +1,7 @@
|
|||||||
http = require("socket.http")
|
http = require("socket.http")
|
||||||
URL = require("socket.url")
|
URL = require("socket.url")
|
||||||
json = (loadfile "./bot/JSON.lua")()
|
json = (loadfile "./bot/JSON.lua")()
|
||||||
lrexlib = require("rex_pcre")
|
-- lrexlib = require("rex_pcre")
|
||||||
|
|
||||||
VERSION = 'v0.6'
|
VERSION = 'v0.6'
|
||||||
|
|
||||||
@ -123,16 +123,17 @@
|
|||||||
-- Where magic happens
|
-- Where magic happens
|
||||||
function do_action(msg)
|
function do_action(msg)
|
||||||
local receiver = get_receiver(msg)
|
local receiver = get_receiver(msg)
|
||||||
local text = msg.text:sub(2) -- removes the '!'
|
--local text = msg.text:sub(2) -- removes the '!'
|
||||||
print("Received msg", msg.text)
|
local text = msg.text
|
||||||
|
print("Received msg", text)
|
||||||
for name, desc in pairs(plugins) do
|
for name, desc in pairs(plugins) do
|
||||||
regexp = desc.regexp
|
print("Trying module", name)
|
||||||
runmethod = desc.run
|
for k, pattern in pairs(desc.patterns) do
|
||||||
print("Trying", text, "against", regexp)
|
print("Trying", text, "against", pattern)
|
||||||
matches = { string.match(text, regexp) }
|
matches = { string.match(text, pattern) }
|
||||||
if matches[1] then
|
if matches[1] then
|
||||||
print(" matches!")
|
print(" matches!")
|
||||||
result = runmethod(msg, matches)
|
result = desc.run(msg, matches)
|
||||||
print(" should return", result)
|
print(" should return", result)
|
||||||
if (result) then
|
if (result) then
|
||||||
send_msg(receiver, result, ok_cb, false)
|
send_msg(receiver, result, ok_cb, false)
|
||||||
@ -140,6 +141,7 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- function do_action(msg)
|
-- function do_action(msg)
|
||||||
-- local receiver = get_receiver(msg)
|
-- local receiver = get_receiver(msg)
|
||||||
|
@ -21,9 +21,9 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "send random url image from 9gag",
|
description = "send random image from 9gag",
|
||||||
usage = "9gag",
|
usage = "!9gag",
|
||||||
regexp = "^9gag$",
|
patterns = {"^!9gag$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "echoes the msg",
|
description = "echoes the msg",
|
||||||
usage = "echo [whatever]",
|
usage = "!echo [whatever]",
|
||||||
regexp = "^echo (.*)$",
|
patterns = {"^!echo (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "EURUSD market value",
|
description = "EURUSD market value",
|
||||||
usage = "eur [USD]",
|
usage = "!eur [USD]",
|
||||||
regexp = "^eur (%d+[%d%.]*)$",
|
patterns = {"^!eur (%d+[%d%.]*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Fortunes from Universidad Carlos III",
|
description = "Fortunes from Universidad Carlos III",
|
||||||
usage = "uc3m",
|
usage = "!uc3m",
|
||||||
regexp = "^uc3m$",
|
patterns = {"^!uc3m$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ end
|
|||||||
return {
|
return {
|
||||||
description = "Says hello to someone",
|
description = "Says hello to someone",
|
||||||
usage = "say hello to [name]",
|
usage = "say hello to [name]",
|
||||||
regexp = "^say hello to (.*)$",
|
patterns = {"^say hello to (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Lists all available commands",
|
description = "Lists all available commands",
|
||||||
usage = "help",
|
usage = "!help",
|
||||||
regexp = "^help$",
|
patterns = {"^!help$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "search image with Google API and sends it",
|
description = "search image with Google API and sends it",
|
||||||
usage = "img [topic]",
|
usage = "!img [topic]",
|
||||||
regexp = "^img (.*)$",
|
patterns = {"^!img (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
@ -7,8 +7,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "bot sends pong",
|
description = "bot sends pong",
|
||||||
usage = "ping",
|
usage = "!ping",
|
||||||
regexp = "^ping$",
|
patterns = {"^!ping$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Spanish dictionary",
|
description = "Spanish dictionary",
|
||||||
usage = "rae [word]",
|
usage = "!rae [word]",
|
||||||
regexp = "^rae (.*)$",
|
patterns = {"^!rae (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Shows the bot version",
|
description = "Shows the bot version",
|
||||||
usage = "version",
|
usage = "!version",
|
||||||
regexp = "^version$",
|
patterns = {"^!version$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
description = "weather in that city (Madrid is default)",
|
description = "weather in that city (Madrid is default)",
|
||||||
usage = "weather [city]",
|
usage = "!weather (city)",
|
||||||
regexp = "^weather(.*)$",
|
patterns = {"^!weather(.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user