This commit is contained in:
topkecleon 2016-08-15 01:00:24 -04:00
parent 738b45cdbd
commit f9094a73ca
12 changed files with 234 additions and 216 deletions

9
.gitignore vendored
View File

@ -1,4 +1,5 @@
otouto/plugins/mokubot*
otouto/plugins/oubot*
*.db
tg
# https://github.com/topkecleon/otouto-plugins-topkecleon
otouto/plugins/mokubot.lua
otouto/plugins/oubot.lua
otouto/plugins/qtbot.lua
otouto/plugins/weeabot.lua

View File

@ -1,13 +1,13 @@
--[[
drua-tg
Based on JuanPotato's lua-tg (https://github.com/juanpotato/lua-tg),
modified to work more naturally from an API bot.
drua-tg
Based on JuanPotato's lua-tg (https://github.com/juanpotato/lua-tg),
modified to work more naturally from an API bot.
Usage:
drua = require('drua-tg')
drua.IP = 'localhost' -- 'localhost' is default
drua.PORT = 4567 -- 4567 is default
drua.message(chat_id, text)
Usage:
drua = require('drua-tg')
drua.IP = 'localhost' -- 'localhost' is default
drua.PORT = 4567 -- 4567 is default
drua.message(chat_id, text)
The MIT License (MIT)
@ -35,150 +35,150 @@ SOFTWARE.
local SOCKET = require('socket')
local comtab = {
add = { 'chat_add_user %s %s', 'channel_invite %s %s' },
kick = { 'chat_del_user %s %s', 'channel_kick %s %s' },
rename = { 'rename_chat %s "%s"', 'rename_channel %s "%s"' },
link = { 'export_chat_link %s', 'export_channel_link %s' },
photo_set = { 'chat_set_photo %s %s', 'channel_set_photo %s %s' },
photo_get = { [0] = 'load_user_photo %s', 'load_chat_photo %s', 'load_channel_photo %s' },
info = { [0] = 'user_info %s', 'chat_info %s', 'channel_info %s' }
add = { 'chat_add_user %s %s', 'channel_invite %s %s' },
kick = { 'chat_del_user %s %s', 'channel_kick %s %s' },
rename = { 'rename_chat %s "%s"', 'rename_channel %s "%s"' },
link = { 'export_chat_link %s', 'export_channel_link %s' },
photo_set = { 'chat_set_photo %s %s', 'channel_set_photo %s %s' },
photo_get = { [0] = 'load_user_photo %s', 'load_chat_photo %s', 'load_channel_photo %s' },
info = { [0] = 'user_info %s', 'chat_info %s', 'channel_info %s' }
}
local format_target = function(target)
target = tonumber(target)
if target < -1000000000000 then
target = 'channel#' .. math.abs(target) - 1000000000000
return target, 2
elseif target < 0 then
target = 'chat#' .. math.abs(target)
return target, 1
else
target = 'user#' .. target
return target, 0
end
local function format_target(target)
target = tonumber(target)
if target < -1000000000000 then
target = 'channel#' .. math.abs(target) - 1000000000000
return target, 2
elseif target < 0 then
target = 'chat#' .. math.abs(target)
return target, 1
else
target = 'user#' .. target
return target, 0
end
end
local escape = function(text)
text = text:gsub('\\', '\\\\')
text = text:gsub('\n', '\\n')
text = text:gsub('\t', '\\t')
text = text:gsub('"', '\\"')
return text
local function escape(text)
text = text:gsub('\\', '\\\\')
text = text:gsub('\n', '\\n')
text = text:gsub('\t', '\\t')
text = text:gsub('"', '\\"')
return text
end
local drua = {
IP = 'localhost',
PORT = 4567
IP = 'localhost',
PORT = 4567
}
drua.send = function(command, do_receive)
local s = SOCKET.connect(drua.IP, drua.PORT)
assert(s, '\nUnable to connect to tg session.')
s:send(command..'\n')
local output
if do_receive then
output = string.match(s:receive('*l'), 'ANSWER (%d+)')
output = s:receive(tonumber(output)):gsub('\n$', '')
end
s:close()
return output
function drua.send(command, do_receive)
local s = SOCKET.connect(drua.IP, drua.PORT)
assert(s, '\nUnable to connect to tg session.')
s:send(command..'\n')
local output
if do_receive then
output = string.match(s:receive('*l'), 'ANSWER (%d+)')
output = s:receive(tonumber(output)):gsub('\n$', '')
end
s:close()
return output
end
drua.message = function(target, text)
target = format_target(target)
text = escape(text)
local command = 'msg %s "%s"'
command = command:format(target, text)
return drua.send(command)
function drua.message(target, text)
target = format_target(target)
text = escape(text)
local command = 'msg %s "%s"'
command = command:format(target, text)
return drua.send(command)
end
drua.send_photo = function(target, photo)
target = format_target(target)
local command = 'send_photo %s %s'
command = command:format(target, photo)
return drua.send(command)
function drua.send_photo(target, photo)
target = format_target(target)
local command = 'send_photo %s %s'
command = command:format(target, photo)
return drua.send(command)
end
drua.add_user = function(chat, target)
local a
chat, a = format_target(chat)
target = format_target(target)
local command = comtab.add[a]:format(chat, target)
return drua.send(command)
function drua.add_user(chat, target)
local a
chat, a = format_target(chat)
target = format_target(target)
local command = comtab.add[a]:format(chat, target)
return drua.send(command)
end
drua.kick_user = function(chat, target)
-- Get the group info so tg will recognize the target.
drua.get_info(chat)
local a
chat, a = format_target(chat)
target = format_target(target)
local command = comtab.kick[a]:format(chat, target)
return drua.send(command)
function drua.kick_user(chat, target)
-- Get the group info so tg will recognize the target.
drua.get_info(chat)
local a
chat, a = format_target(chat)
target = format_target(target)
local command = comtab.kick[a]:format(chat, target)
return drua.send(command)
end
drua.rename_chat = function(chat, name)
local a
chat, a = format_target(chat)
local command = comtab.rename[a]:format(chat, name)
return drua.send(command)
function drua.rename_chat(chat, name)
local a
chat, a = format_target(chat)
local command = comtab.rename[a]:format(chat, name)
return drua.send(command)
end
drua.export_link = function(chat)
local a
chat, a = format_target(chat)
local command = comtab.link[a]:format(chat)
return drua.send(command, true)
function drua.export_link(chat)
local a
chat, a = format_target(chat)
local command = comtab.link[a]:format(chat)
return drua.send(command, true)
end
drua.get_photo = function(chat)
local a
chat, a = format_target(chat)
local command = comtab.photo_get[a]:format(chat)
local output = drua.send(command, true)
if output:match('FAIL') then
return false
else
return output:match('Saved to (.+)')
end
function drua.get_photo(chat)
local a
chat, a = format_target(chat)
local command = comtab.photo_get[a]:format(chat)
local output = drua.send(command, true)
if output:match('FAIL') then
return false
else
return output:match('Saved to (.+)')
end
end
drua.set_photo = function(chat, photo)
local a
chat, a = format_target(chat)
local command = comtab.photo_set[a]:format(chat, photo)
return drua.send(command)
function drua.set_photo(chat, photo)
local a
chat, a = format_target(chat)
local command = comtab.photo_set[a]:format(chat, photo)
return drua.send(command)
end
drua.get_info = function(target)
local a
target, a = format_target(target)
local command = comtab.info[a]:format(target)
return drua.send(command, true)
function drua.get_info(target)
local a
target, a = format_target(target)
local command = comtab.info[a]:format(target)
return drua.send(command, true)
end
drua.channel_set_admin = function(chat, user, rank)
chat = format_target(chat)
user = format_target(user)
local command = 'channel_set_admin %s %s %s'
command = command:format(chat, user, rank)
return drua.send(command)
function drua.channel_set_admin(chat, user, rank)
chat = format_target(chat)
user = format_target(user)
local command = 'channel_set_admin %s %s %s'
command = command:format(chat, user, rank)
return drua.send(command)
end
drua.channel_set_about = function(chat, text)
chat = format_target(chat)
text = escape(text)
local command = 'channel_set_about %s "%s"'
command = command:format(chat, text)
return drua.send(command)
function drua.channel_set_about(chat, text)
chat = format_target(chat)
text = escape(text)
local command = 'channel_set_about %s "%s"'
command = command:format(chat, text)
return drua.send(command)
end
drua.block = function(user)
return drua.send('block_user user#' .. user)
function drua.block(user)
return drua.send('block_user user#' .. user)
end
drua.unblock = function(user)
return drua.send('unblock_user user#' .. user)
function drua.unblock(user)
return drua.send('unblock_user user#' .. user)
end
return drua

View File

@ -50,17 +50,7 @@ function administration:init(config)
administration.flags = administration.init_flags(config.cmd_pat)
administration.init_command(self, config)
administration.antiflood = config.administration.antiflood or {
text = 5,
voice = 5,
audio = 5,
contact = 5,
photo = 10,
video = 10,
location = 10,
document = 10,
sticker = 20
}
administration.antiflood = config.administration.antiflood
administration.doc = 'Returns a list of administrated groups.\nUse '..config.cmd_pat..'ahelp for more administrative commands.'
administration.command = 'groups [query]'

View File

@ -34,7 +34,7 @@ function bible:action(msg, config)
output, res = HTTP.request(url)
end
if not output or res ~= 200 or output:len() == 0 then
if not output or res ~= 200 or output:len() == 0 then
output = config.errors.results
end

View File

@ -0,0 +1,40 @@
--[[
This plugin causes the bot to respond to certain triggers over the owner's
account, via drua-tg.
It's basically the greetings plugin with drua instead of bot output.
It will also uppercase the output if the input is entirely uppercase.
]]
local drua = require('otouto.drua-tg')
local druasay = {}
function druasay:init(config)
druasay.triggers = {}
for _, triggers in pairs(config.druasay) do
for i = 1, #triggers do
table.insert(druasay.triggers, triggers[i])
end
end
druasay.error = false
end
function druasay:action(msg, config)
if msg.from.id == config.admin or msg.chat.type == 'private' then return end
for response, triggers in pairs(config.druasay) do
for _, trigger in ipairs(triggers) do
if msg.text_lower:match(trigger) then
local output
if msg.text == msg.text:upper() then
output = response:upper()
else
output = response
end
drua.message(msg.chat.id, output)
return
end
end
end
end
return druasay

View File

@ -41,7 +41,7 @@ function me:action(msg, config)
local data = {}
for k,v in pairs(userdata) do
table.insert(data, string.format(
'<b>%s</b> <code>%s</code>\n',
'<b>%s:</b> <code>%s</code>\n',
utilities.html_escape(k),
utilities.html_escape(v)
))

View File

@ -13,7 +13,7 @@ Example (forty pidgeys and three hundred pidgey candies):
end
-- This function written by Juan Potato. MIT-licensed.
local pidgey_calc = function(candies_to_evolve, mons, candies)
local function pidgey_calc(candies_to_evolve, mons, candies)
local transferred = 0;
local evolved = 0;
@ -52,7 +52,7 @@ local pidgey_calc = function(candies_to_evolve, mons, candies)
}
end
local single_job = function(input)
local function single_job(input)
local req_candy, mons, candies = input:match('^(%d+) (%d+) (%d+)$')
req_candy = tonumber(req_candy)
mons = tonumber(mons)

View File

@ -6,79 +6,79 @@ local utilities = require('otouto.utilities')
pokemon_go.command = 'pokego <team>'
function pokemon_go:init(config)
pokemon_go.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('pokego', true):t('pokégo', true)
:t('pokemongo', true):t('pokémongo', true)
:t('pogo', true):t('mongo', true).table
pokemon_go.doc = config.cmd_pat .. [[pokego <team>
pokemon_go.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('pokego', true):t('pokégo', true)
:t('pokemongo', true):t('pokémongo', true)
:t('pogo', true):t('mongo', true).table
pokemon_go.doc = config.cmd_pat .. [[pokego <team>
Set your Pokémon Go team for statistical purposes. The team must be valid, and can be referred to by name or color (or the first letter of either). Giving no team name will show statistics.]]
local db = self.database.pokemon_go
if not db then
self.database.pokemon_go = {}
db = self.database.pokemon_go
end
if not db.membership then
db.membership = {}
end
for _, set in pairs(db.membership) do
setmetatable(set, utilities.set_meta)
end
local db = self.database.pokemon_go
if not db then
self.database.pokemon_go = {}
db = self.database.pokemon_go
end
if not db.membership then
db.membership = {}
end
for _, set in pairs(db.membership) do
setmetatable(set, utilities.set_meta)
end
end
local team_ref = {
mystic = "Mystic",
m = "Mystic",
valor = "Valor",
v = "Valor",
instinct = "Instinct",
i = "Instinct",
blue = "Mystic",
b = "Mystic",
red = "Valor",
r = "Valor",
yellow = "Instinct",
y = "Instinct"
mystic = "Mystic",
m = "Mystic",
valor = "Valor",
v = "Valor",
instinct = "Instinct",
i = "Instinct",
blue = "Mystic",
b = "Mystic",
red = "Valor",
r = "Valor",
yellow = "Instinct",
y = "Instinct"
}
function pokemon_go:action(msg, config)
local output
local input = utilities.input(msg.text_lower)
local output
local input = utilities.input(msg.text_lower)
if input then
local team = team_ref[input]
if not team then
output = 'Invalid team.'
else
local id_str = tostring(msg.from.id)
local db = self.database.pokemon_go
local db_membership = db.membership
if not db_membership[team] then
db_membership[team] = utilities.new_set()
end
for t, set in pairs(db_membership) do
if t ~= team then
set:remove(id_str)
if input then
local team = team_ref[input]
if not team then
output = 'Invalid team.'
else
set:add(id_str)
local id_str = tostring(msg.from.id)
local db = self.database.pokemon_go
local db_membership = db.membership
if not db_membership[team] then
db_membership[team] = utilities.new_set()
end
for t, set in pairs(db_membership) do
if t ~= team then
set:remove(id_str)
else
set:add(id_str)
end
end
output = 'Your team is now '..team..'.'
end
end
else
local db = self.database.pokemon_go
local db_membership = db.membership
output = 'Your team is now '..team..'.'
end
else
local db = self.database.pokemon_go
local db_membership = db.membership
local output_temp = {'Membership:'}
for t, set in pairs(db_membership) do
table.insert(output_temp, t..': '..#set)
end
local output_temp = {'Membership:'}
for t, set in pairs(db_membership) do
table.insert(output_temp, t..': '..#set)
output = table.concat(output_temp, '\n')
end
output = table.concat(output_temp, '\n')
end
utilities.send_reply(self, msg, output)
utilities.send_reply(self, msg, output)
end
return pokemon_go

View File

@ -67,7 +67,7 @@ local puns = {
"I don't trust people with graph paper. They're always plotting something",
"I had a friend who was addicted to brake fluid. He says he can stop anytime.",
"The form said I had Type A blood, but it was a Type O.",
"I went to to the shop to buy eight Sprites - I came home and realised I'd picked 7Up.",
"I went to to the shop to buy eight Sprites - I came home and realised I'd picked 7Up.",
"There was an explosion at a pie factory. 3.14 people died.",
"A man drove his car into a tree and found out how a Mercedes bends.",
"The experienced carpenter really nailed it, but the new guy screwed everything up.",

View File

@ -1,11 +1,3 @@
-- Never change this plugin. It was not meant to be changed.
-- You may add reactions. You must never remove reactions.
-- You must never restructure. You must never disable this plugin.
-- - Drew, creator, a year later.
-- Nevermind, Brayden changed it.
-- - Drew, just now.
local reactions = {}
local utilities = require('otouto.utilities')
@ -13,15 +5,13 @@ local utilities = require('otouto.utilities')
reactions.command = 'reactions'
reactions.doc = 'Returns a list of "reaction" emoticon commands.'
local help
function reactions:init(config)
-- Generate a "help" message triggered by "/reactions".
help = 'Reactions:\n'
-- Generate a command list message triggered by "/reactions".
reactions.help = 'Reactions:\n'
reactions.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('reactions').table
local username = self.info.username:lower()
for trigger,reaction in pairs(config.reactions) do
help = help .. '' .. config.cmd_pat .. trigger .. ': ' .. reaction .. '\n'
for trigger, reaction in pairs(config.reactions) do
reactions.help = reactions.help .. '' .. config.cmd_pat .. trigger .. ': ' .. reaction .. '\n'
table.insert(reactions.triggers, '^'..config.cmd_pat..trigger)
table.insert(reactions.triggers, '^'..config.cmd_pat..trigger..'@'..username)
table.insert(reactions.triggers, config.cmd_pat..trigger..'$')
@ -35,12 +25,12 @@ end
function reactions:action(msg, config)
if string.match(msg.text_lower, config.cmd_pat..'reactions') then
utilities.send_message(self, msg.chat.id, help)
utilities.send_message(self, msg.chat.id, reactions.help, true, nil, 'html')
return
end
for trigger,reaction in pairs(config.reactions) do
if string.match(msg.text_lower, config.cmd_pat..trigger) then
utilities.send_message(self, msg.chat.id, reaction)
utilities.send_message(self, msg.chat.id, reaction, true, nil, 'html')
return
end
end

View File

@ -14,7 +14,7 @@ Returns the top posts or results for a given subreddit or query. If no argument
Aliases: ]] .. config.cmd_pat .. 'r, /r/subreddit'
end
local format_results = function(posts)
local function format_results(posts)
local output = ''
for _,v in ipairs(posts) do
local post = v.data

View File

@ -9,9 +9,6 @@ function remind:init(config)
remind.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('remind', true).table
config.remind = config.remind or {}
setmetatable(config.remind, { __index = function() return 1000 end })
remind.doc = config.cmd_pat .. [[remind <duration> <message>
Repeats a message after a duration of time, in minutes.
The maximum length of a reminder is %s characters. The maximum duration of a timer is %s minutes. The maximum number of reminders for a group is %s. The maximum number of reminders in private is %s.]]