fixed default config

rewrote get_word()
This commit is contained in:
topkecleon 2015-12-13 16:31:22 -05:00
parent a0bbdba135
commit c827004bc7
4 changed files with 22 additions and 34 deletions

12
bot.lua
View File

@ -40,13 +40,15 @@ on_msg_receive = function(msg) -- The fn run whenever a message is received.
if msg.date < os.time() - 5 then return end -- Do not process old messages.
if not msg.text then msg.text = msg.caption or '' end
msg.chat.id_str = tostring(msg.chat.id)
msg.from.id_str = tostring(msg.from.id)
msg.text_lower = msg.text:lower()
for i,v in ipairs(plugins) do
for k,w in pairs(v.triggers) do
if string.match(msg.text_lower, w) then
if string.match(msg.text:lower(), w) then
-- a few shortcuts
msg.chat.id_str = tostring(msg.chat.id)
msg.from.id_str = tostring(msg.from.id)
msg.text_lower = msg.text:lower()
local success, result = pcall(function()
return v.action(msg)
end)

View File

@ -65,7 +65,7 @@ telegram.me/otouto
plugins = {
'blacklist.lua',
'floodcontrol.lua',
'admin.lua',
'control.lua',
'about.lua',
'ping.lua',
'whoami.lua',

View File

@ -7,10 +7,10 @@
'^/modhelp[@'..bot.username..']*$',
'^/modlist[@'..bot.username..']*$',
'^/modcast[@'..bot.username..']*',
'^/add[@'..bot.username..']*$',
'^/remove[@'..bot.username..']*$',
'^/promote[@'..bot.username..']*$',
'^/demote[@'..bot.username..']*',
'^/modadd[@'..bot.username..']*$',
'^/modrem[@'..bot.username..']*$',
'^/modprom[@'..bot.username..']*$',
'^/moddem[@'..bot.username..']*',
'^/modkick[@'..bot.username..']*',
'^/modban[@'..bot.username..']*',
}
@ -94,7 +94,7 @@ local commands = {
end,
['^/add[@'..bot.username..']*$'] = function(msg)
['^/modadd[@'..bot.username..']*$'] = function(msg)
if not config.moderation.admins[msg.from.id_str] then
return config.errors.not_admin
@ -112,7 +112,7 @@ local commands = {
end,
['^/remove[@'..bot.username..']*$'] = function(msg)
['^/modrem[@'..bot.username..']*$'] = function(msg)
if not config.moderation.admins[msg.from.id_str] then
return config.errors.not_admin
@ -130,7 +130,7 @@ local commands = {
end,
['^/promote[@'..bot.username..']*$'] = function(msg)
['^/modprom[@'..bot.username..']*$'] = function(msg)
local moddat = load_data('moderation.json')
@ -164,7 +164,7 @@ local commands = {
end,
['^/demote[@'..bot.username..']*'] = function(msg)
['^/moddem[@'..bot.username..']*'] = function(msg)
local moddat = load_data('moderation.json')
@ -279,7 +279,7 @@ local commands = {
local action = function(msg)
for k,v in pairs(commands) do
if string.match(msg.text, k) then
if string.match(msg.text_lower, k) then
local output = v(msg)
if output then
sendReply(msg, output)

View File

@ -1,28 +1,14 @@
-- utilities.lua
-- Functions shared among plugins.
function get_word(str, idx) -- get the indexed word in a string
function get_word(s, i) -- get the indexed word in a string
local str = str:gsub('^%s*(.-)%s*$', '%1')
str = string.gsub(str, '\n', ' ')
if not string.find(str, ' ') then
if idx == 1 then
return str
else
return false
end
local t = {}
for w in s:gmatch('%g+') do
table.insert(t, w)
end
str = str .. ' '
if idx ~= 1 then
for i = 2, idx do
str = string.sub(str, string.find(str, ' ') + 1)
end
end
str = str:sub(1, str:find(' '))
return str:sub(1, -2)
return t[i] or false
end