Fixe ein ziemlich seltsames Problem mit /plugins
This commit is contained in:
@ -28,14 +28,12 @@ function bot:init(config) -- The function run when the bot is started or reloade
|
||||
|
||||
self.plugins = {} -- Load plugins.
|
||||
enabled_plugins = load_plugins()
|
||||
t = {}
|
||||
for k,v in pairs(enabled_plugins) do
|
||||
local p = require('otouto.plugins.'..v)
|
||||
-- print('loading plugin',v)
|
||||
self.plugins[k] = p
|
||||
self.plugins[k].name = v
|
||||
if p.init then p.init(self, config) end
|
||||
if not p.triggers then p.triggers = t end
|
||||
end
|
||||
|
||||
print('Bot started successfully as:\n@' .. self.info.username .. ', AKA ' .. self.info.first_name ..' ('..self.info.id..')')
|
||||
@ -45,7 +43,6 @@ function bot:init(config) -- The function run when the bot is started or reloade
|
||||
self.last_cron = self.last_cron or os.date('%M') -- Last cron job.
|
||||
self.last_database_save = self.last_database_save or os.date('%H') -- Last db save.
|
||||
self.is_started = true -- and whether or not the bot should be running.
|
||||
|
||||
end
|
||||
|
||||
function bot:on_msg_receive(msg, config) -- The fn run whenever a message is received.
|
||||
@ -79,10 +76,9 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
|
||||
msg = service_modify_msg(msg)
|
||||
end
|
||||
|
||||
for n=1, #self.plugins do
|
||||
local plugin = self.plugins[n]
|
||||
match_plugins(self, msg, config, plugin)
|
||||
end
|
||||
for _, plugin in ipairs(self.plugins) do
|
||||
match_plugins(self, msg, config, plugin)
|
||||
end
|
||||
end
|
||||
|
||||
function bot:on_callback_receive(callback, msg, config) -- whenever a new callback is received
|
||||
@ -182,12 +178,12 @@ function bot:process_inline_query(inline_query, config) -- When an inline query
|
||||
utilities.answer_inline_query(self, inline_query, nil, 0, true)
|
||||
end
|
||||
|
||||
-- main
|
||||
function bot:run(config)
|
||||
bot.init(self, config)
|
||||
|
||||
while self.is_started do
|
||||
-- Update loop
|
||||
local res = bindings.getUpdates(self, { timeout = 20, offset = self.last_update + 1 } )
|
||||
local res = bindings.getUpdates(self, { timeout = 20, offset = self.last_update+1 } )
|
||||
if res then
|
||||
-- Iterate over every new message.
|
||||
for n=1, #res.result do
|
||||
@ -205,7 +201,7 @@ function bot:run(config)
|
||||
print('Connection error while fetching updates.')
|
||||
end
|
||||
|
||||
-- Run cron jobs every minute.
|
||||
-- Run cron jobs every minute.
|
||||
if self.last_cron ~= os.date('%M') then
|
||||
self.last_cron = os.date('%M')
|
||||
utilities.save_data(self.info.username..'.db', self.database) -- Save the database.
|
||||
@ -262,7 +258,7 @@ function match_inline_plugins(self, inline_query, config, plugin)
|
||||
end
|
||||
|
||||
function match_plugins(self, msg, config, plugin)
|
||||
local match_table = plugin.triggers
|
||||
local match_table = plugin.triggers or {}
|
||||
for n=1, #match_table do
|
||||
local trigger = plugin.triggers[n]
|
||||
if string.match(msg.text_lower, trigger) then
|
||||
|
Reference in New Issue
Block a user