diff --git a/otouto/bot.lua b/otouto/bot.lua index dc2aba4..313e2ca 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -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 diff --git a/otouto/plugins/plugins.lua b/otouto/plugins/plugins.lua index 019f176..38f2530 100644 --- a/otouto/plugins/plugins.lua +++ b/otouto/plugins/plugins.lua @@ -5,12 +5,12 @@ local bot = require('otouto.bot') function plugin_manager:init(config) plugin_manager.triggers = { "^/plugins$", + "^/plugins? (enable) ([%w_%.%-]+) (chat) (%d+)$", + "^/plugins? (enable) ([%w_%.%-]+) (chat)$", + "^/plugins? (disable) ([%w_%.%-]+) (chat) (%d+)$", + "^/plugins? (disable) ([%w_%.%-]+) (chat)$", "^/plugins? (enable) ([%w_%.%-]+)$", "^/plugins? (disable) ([%w_%.%-]+)$", - "^/plugins? (enable) ([%w_%.%-]+) (chat) (%d+)", - "^/plugins? (enable) ([%w_%.%-]+) (chat)", - "^/plugins? (disable) ([%w_%.%-]+) (chat) (%d+)", - "^/plugins? (disable) ([%w_%.%-]+) (chat)", "^/plugins? (reload)$", "^/(reload)$" } diff --git a/otouto/plugins/preview.lua b/otouto/plugins/preview.lua index fd28085..6948487 100644 --- a/otouto/plugins/preview.lua +++ b/otouto/plugins/preview.lua @@ -4,10 +4,9 @@ preview.command = 'preview ' function preview:init(config) preview.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('preview', true).table - preview.doc = [[``` -]]..config.cmd_pat..[[preview -Returns a full-message, "unlinked" preview. -```]] + preview.doc = [[* +]]..config.cmd_pat..[[preview* __ +Erstellt einen Preview-Link]] end function preview:action(msg)