Let's get this rock rolling!
This commit is contained in:
parent
41181085ce
commit
46343a5503
@ -67,9 +67,9 @@ function bindings:sendMessage(chat_id, text, disable_web_page_preview, reply_to_
|
|||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
10
bot.lua
10
bot.lua
@ -1,12 +1,16 @@
|
|||||||
local bot = {}
|
local bot = {}
|
||||||
|
|
||||||
local bindings = require('bindings') -- Load Telegram bindings.
|
-- Requires are moved to init to allow for reloads.
|
||||||
local utilities = require('utilities') -- Load miscellaneous and cross-plugin functions.
|
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.
|
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.config = require('config') -- Load configuration file.
|
||||||
|
|
||||||
self.BASE_URL = 'https://api.telegram.org/bot' .. self.config.bot_api_key
|
self.BASE_URL = 'https://api.telegram.org/bot' .. self.config.bot_api_key
|
||||||
|
22
otouto-dev-1.rockspec
Normal file
22
otouto-dev-1.rockspec
Normal 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'
|
||||||
|
}
|
@ -1063,7 +1063,7 @@ function administration.init_command(self_)
|
|||||||
local input = utilities.input(msg.text) or msg.chat.id_str
|
local input = utilities.input(msg.text) or msg.chat.id_str
|
||||||
local output
|
local output
|
||||||
if self.database.administration.groups[input] then
|
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
|
self.database.administration.groups[input] = nil
|
||||||
for i,v in ipairs(self.database.administration.activity) do
|
for i,v in ipairs(self.database.administration.activity) do
|
||||||
if v == input then
|
if v == input then
|
||||||
|
@ -29,7 +29,7 @@ function bandersnatch:action(msg)
|
|||||||
output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
|
output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
|
||||||
end
|
end
|
||||||
|
|
||||||
bindings.sendReply(self, msg, output)
|
bindings.sendMessage(self, msg.chat.id, '_'..output..'_', true, nil, true)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ function calc:action(msg)
|
|||||||
if msg.reply_to_message and msg.reply_to_message.text then
|
if msg.reply_to_message and msg.reply_to_message.text then
|
||||||
input = msg.reply_to_message.text
|
input = msg.reply_to_message.text
|
||||||
else
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,14 @@ function control:action(msg)
|
|||||||
if msg.date < os.time() - 1 then return end
|
if msg.date < os.time() - 1 then return end
|
||||||
|
|
||||||
if msg.text:match('^'..utilities.INVOCATION_PATTERN..'reload') then
|
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)
|
bot.init(self)
|
||||||
bindings.sendReply(self, msg, 'Bot reloaded!')
|
bindings.sendReply(self, msg, 'Bot reloaded!')
|
||||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
||||||
|
@ -52,7 +52,8 @@ function currency:action(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n\n'
|
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)
|
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ function imdb:action(msg)
|
|||||||
local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')*\n'
|
local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')*\n'
|
||||||
output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
||||||
output = output .. '_' .. jdat.Plot .. '_\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)
|
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ function luarun:action(msg)
|
|||||||
return
|
return
|
||||||
end
|
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
|
if output == nil then
|
||||||
output = 'Done!'
|
output = 'Done!'
|
||||||
elseif type(output) == 'table' then
|
elseif type(output) == 'table' then
|
||||||
|
@ -24,17 +24,17 @@ local help
|
|||||||
|
|
||||||
function reactions:init()
|
function reactions:init()
|
||||||
-- Generate a "help" message triggered by "/reactions".
|
-- Generate a "help" message triggered by "/reactions".
|
||||||
local help = 'Reactions:\n'
|
help = 'Reactions:\n'
|
||||||
reactions.triggers = utilities.triggers(self.info.username):t('reactions').table
|
reactions.triggers = utilities.triggers(self.info.username):t('reactions').table
|
||||||
for trigger,reaction in pairs(mapping) do
|
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)
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
function reactions:action(msg)
|
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)
|
bindings.sendMessage(self, msg.chat.id, help)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ end
|
|||||||
|
|
||||||
function remind:action(msg)
|
function remind:action(msg)
|
||||||
-- Ensure there are arguments. If not, send doc.
|
-- Ensure there are arguments. If not, send doc.
|
||||||
local input = msg.text:input()
|
local input = utilities.input(msg.text)
|
||||||
if not input then
|
if not input then
|
||||||
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||||
return
|
return
|
||||||
@ -36,7 +36,7 @@ function remind:action(msg)
|
|||||||
duration = 526000
|
duration = 526000
|
||||||
end
|
end
|
||||||
-- Ensure there is a second arg.
|
-- Ensure there is a second arg.
|
||||||
local message = input:input()
|
local message = utilities.input(input)
|
||||||
if not message then
|
if not message then
|
||||||
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
bindings.sendMessage(self, msg.chat.id, remind.doc, true, msg.message_id, true)
|
||||||
return
|
return
|
||||||
|
@ -53,9 +53,10 @@ function time:action(msg)
|
|||||||
else
|
else
|
||||||
utcoff = utilities.pretty_float(utcoff)
|
utcoff = utilities.pretty_float(utcoff)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ function translate:action(msg)
|
|||||||
local output = jdat.text[1]
|
local output = jdat.text[1]
|
||||||
output = '*Translation:*\n"' .. utilities.md_escape(output) .. '"'
|
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
|
end
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ function weather:action(msg)
|
|||||||
local fahrenheit = string.format('%.2f', celsius * (9/5) + 32)
|
local fahrenheit = string.format('%.2f', celsius * (9/5) + 32)
|
||||||
local output = '`' .. celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.`'
|
local output = '`' .. celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.`'
|
||||||
|
|
||||||
bindings.sendReply(self, msg, output)
|
bindings.sendReply(self, msg, output, true)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user