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

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 msg.date < os.time() - 5 then return end -- Do not process old messages.
if not msg.text then msg.text = msg.caption or '' end if not msg.text then msg.text = msg.caption or '' end
for i,v in ipairs(plugins) do
for k,w in pairs(v.triggers) do
if string.match(msg.text:lower(), w) then
-- a few shortcuts
msg.chat.id_str = tostring(msg.chat.id) msg.chat.id_str = tostring(msg.chat.id)
msg.from.id_str = tostring(msg.from.id) msg.from.id_str = tostring(msg.from.id)
msg.text_lower = msg.text:lower() 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
local success, result = pcall(function() local success, result = pcall(function()
return v.action(msg) return v.action(msg)
end) end)

View File

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

View File

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

View File

@ -1,28 +1,14 @@
-- utilities.lua -- utilities.lua
-- Functions shared among plugins. -- 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') local t = {}
for w in s:gmatch('%g+') do
str = string.gsub(str, '\n', ' ') table.insert(t, w)
if not string.find(str, ' ') then
if idx == 1 then
return str
else
return false
end
end end
str = str .. ' ' return t[i] or false
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)
end end