Let's get this rock rolling!

This commit is contained in:
Brayden Banks 2016-04-28 21:36:35 -07:00
parent 41181085ce
commit 46343a5503
15 changed files with 57 additions and 21 deletions

View File

@ -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

10
bot.lua
View File

@ -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

22
otouto-dev-1.rockspec Normal file
View File

@ -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 <drew@otou.to>',
license = 'GPL-2'
}
dependencies = {
'lua >= 5.2',
'LuaSocket ~> 3.0',
'LuaSec ~> 0.6',
'dkjson ~> 2.5',
'LPeg ~> 1.0'
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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