diff --git a/bindings.lua b/bindings.lua index 704af41..d303f67 100755 --- a/bindings.lua +++ b/bindings.lua @@ -67,9 +67,9 @@ function bindings:sendMessage(chat_id, text, disable_web_page_preview, reply_to_ end -function bindings:sendReply(msg, text) +function bindings:sendReply(msg, text, use_markdown, disable_notification) - return bindings.sendMessage(self, msg.chat.id, text, true, msg.message_id) + return bindings.sendMessage(self, msg.chat.id, text, true, msg.message_id, use_markdown, disable_notification) end diff --git a/bot.lua b/bot.lua index 25f10f6..a6bea28 100755 --- a/bot.lua +++ b/bot.lua @@ -1,12 +1,16 @@ local bot = {} -local bindings = require('bindings') -- Load Telegram bindings. -local utilities = require('utilities') -- Load miscellaneous and cross-plugin functions. +-- Requires are moved to init to allow for reloads. +local bindings -- Load Telegram bindings. +local utilities -- Load miscellaneous and cross-plugin functions. -bot.version = '3.6' +bot.version = '3.7' function bot:init() -- The function run when the bot is started or reloaded. + bindings = require('bindings') + utilities = require('utilities') + self.config = require('config') -- Load configuration file. self.BASE_URL = 'https://api.telegram.org/bot' .. self.config.bot_api_key diff --git a/otouto-dev-1.rockspec b/otouto-dev-1.rockspec new file mode 100644 index 0000000..86acac1 --- /dev/null +++ b/otouto-dev-1.rockspec @@ -0,0 +1,22 @@ +package = 'otouto' +version = 'dev-1' + +source = { + url = 'git://github.com/topkecleon/otouto.git' +} + +description = { + summary = 'The plugin-wielding, multipurpose Telegram bot!', + detailed = 'A plugin-wielding, multipurpose bot for the Telegram API.', + homepage = 'http://otou.to', + maintainer = 'Drew ', + license = 'GPL-2' +} + +dependencies = { + 'lua >= 5.2', + 'LuaSocket ~> 3.0', + 'LuaSec ~> 0.6', + 'dkjson ~> 2.5', + 'LPeg ~> 1.0' +} diff --git a/plugins/administration.lua b/plugins/administration.lua index 277c816..3f9a39a 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -1063,7 +1063,7 @@ function administration.init_command(self_) local input = utilities.input(msg.text) or msg.chat.id_str local output if self.database.administration.groups[input] then - local chat_name = self.administration.groups[input].name + local chat_name = self.database.administration.groups[input].name self.database.administration.groups[input] = nil for i,v in ipairs(self.database.administration.activity) do if v == input then diff --git a/plugins/bandersnatch.lua b/plugins/bandersnatch.lua index 6d9779f..5d44e81 100755 --- a/plugins/bandersnatch.lua +++ b/plugins/bandersnatch.lua @@ -29,7 +29,7 @@ function bandersnatch:action(msg) output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)] end - bindings.sendReply(self, msg, output) + bindings.sendMessage(self, msg.chat.id, '_'..output..'_', true, nil, true) end diff --git a/plugins/calc.lua b/plugins/calc.lua index 53a5bfd..0ee1070 100755 --- a/plugins/calc.lua +++ b/plugins/calc.lua @@ -22,7 +22,7 @@ function calc:action(msg) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - bindings.sendMessage(msg.chat.id, calc.doc, true, msg.message_id, true) + bindings.sendMessage(self, msg.chat.id, calc.doc, true, msg.message_id, true) return end end diff --git a/plugins/control.lua b/plugins/control.lua index a8f372b..b1c6c75 100644 --- a/plugins/control.lua +++ b/plugins/control.lua @@ -17,6 +17,14 @@ function control:action(msg) if msg.date < os.time() - 1 then return end if msg.text:match('^'..utilities.INVOCATION_PATTERN..'reload') then + for pac, _ in pairs(package.loaded) do + if pac:match('^plugins%.') then + package.loaded[pac] = nil + end + package.loaded['bindings'] = nil + package.loaded['utilities'] = nil + package.loaded['config'] = nil + end bot.init(self) bindings.sendReply(self, msg, 'Bot reloaded!') elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then diff --git a/plugins/currency.lua b/plugins/currency.lua index dc2a935..d4b1936 100755 --- a/plugins/currency.lua +++ b/plugins/currency.lua @@ -52,7 +52,8 @@ function currency:action(msg) end local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n\n' - output = output .. '`' .. os.date('!%F %T UTC') .. '\nSource: Google Finance`' + output = output .. os.date('!%F %T UTC') .. '\nSource: Google Finance`' + output = '```\n' .. output .. '\n```' bindings.sendMessage(self, msg.chat.id, output, true, nil, true) diff --git a/plugins/imdb.lua b/plugins/imdb.lua index 5c142f5..0ee3dd7 100755 --- a/plugins/imdb.lua +++ b/plugins/imdb.lua @@ -46,7 +46,7 @@ function imdb:action(msg) local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')*\n' output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n' output = output .. '_' .. jdat.Plot .. '_\n' - output = output .. '[*Read more*](http://imdb.com/title/' .. jdat.imdbID .. ')' + output = output .. '[Read more.](http://imdb.com/title/' .. jdat.imdbID .. ')' bindings.sendMessage(self, msg.chat.id, output, true, nil, true) diff --git a/plugins/luarun.lua b/plugins/luarun.lua index f88f44d..c416adb 100644 --- a/plugins/luarun.lua +++ b/plugins/luarun.lua @@ -19,7 +19,7 @@ function luarun:action(msg) return end - local output = loadstring('local bindings = require(\'bindings\'); local utilities = require(\'utilities\'); return function (instance, msg) '..input..' end')()(self, msg) + local output = loadstring('local bindings = require(\'bindings\'); local utilities = require(\'utilities\'); return function (self, msg) '..input..' end')()(self, msg) if output == nil then output = 'Done!' elseif type(output) == 'table' then diff --git a/plugins/reactions.lua b/plugins/reactions.lua index 8b73c82..5a08052 100755 --- a/plugins/reactions.lua +++ b/plugins/reactions.lua @@ -24,17 +24,17 @@ local help function reactions:init() -- Generate a "help" message triggered by "/reactions". - local help = 'Reactions:\n' + help = 'Reactions:\n' reactions.triggers = utilities.triggers(self.info.username):t('reactions').table for trigger,reaction in pairs(mapping) do - help = help .. '• ' .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n' + help = help .. '• ' .. utilities.INVOCATION_PATTERN..trigger .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n' table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger) - table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger..'@'..self.username:lower()) + table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger..'@'..self.info.username:lower()) end end function reactions:action(msg) - if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..'help') then + if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..'reactions') then bindings.sendMessage(self, msg.chat.id, help) return end diff --git a/plugins/remind.lua b/plugins/remind.lua index ea6ad94..b4fca96 100644 --- a/plugins/remind.lua +++ b/plugins/remind.lua @@ -17,7 +17,7 @@ end function remind:action(msg) -- Ensure there are arguments. If not, send doc. - local input = msg.text:input() + local input = utilities.input(msg.text) if not input then bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true) return @@ -36,7 +36,7 @@ function remind:action(msg) duration = 526000 end -- Ensure there is a second arg. - local message = input:input() + local message = utilities.input(input) if not message then bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true) return diff --git a/plugins/time.lua b/plugins/time.lua index b3867d6..be47ddd 100755 --- a/plugins/time.lua +++ b/plugins/time.lua @@ -53,9 +53,10 @@ function time:action(msg) else utcoff = utilities.pretty_float(utcoff) end - local output = '`' .. os.date('!%I:%M %p\n', timestamp) .. os.date('!%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')``' + local output = os.date('!%I:%M %p\n', timestamp) .. os.date('!%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')' + output = '```\n' .. output .. '\n```' - bindings.sendReply(self, msg, output) + bindings.sendReply(self, msg, output, true) end diff --git a/plugins/translate.lua b/plugins/translate.lua index 01732ef..204f297 100755 --- a/plugins/translate.lua +++ b/plugins/translate.lua @@ -45,7 +45,7 @@ function translate:action(msg) local output = jdat.text[1] output = '*Translation:*\n"' .. utilities.md_escape(output) .. '"' - bindings.sendReply(self, msg.reply_to_message or msg, output) + bindings.sendReply(self, msg.reply_to_message or msg, output, true) end diff --git a/plugins/weather.lua b/plugins/weather.lua index d06286a..89ea62d 100755 --- a/plugins/weather.lua +++ b/plugins/weather.lua @@ -57,7 +57,7 @@ function weather:action(msg) local fahrenheit = string.format('%.2f', celsius * (9/5) + 32) local output = '`' .. celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.`' - bindings.sendReply(self, msg, output) + bindings.sendReply(self, msg, output, true) end