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* # https://github.com/topkecleon/otouto-plugins-topkecleon
otouto/plugins/oubot* otouto/plugins/mokubot.lua
*.db otouto/plugins/oubot.lua
tg otouto/plugins/qtbot.lua
otouto/plugins/weeabot.lua

View File

@ -44,7 +44,7 @@ local comtab = {
info = { [0] = 'user_info %s', 'chat_info %s', 'channel_info %s' } info = { [0] = 'user_info %s', 'chat_info %s', 'channel_info %s' }
} }
local format_target = function(target) local function format_target(target)
target = tonumber(target) target = tonumber(target)
if target < -1000000000000 then if target < -1000000000000 then
target = 'channel#' .. math.abs(target) - 1000000000000 target = 'channel#' .. math.abs(target) - 1000000000000
@ -58,7 +58,7 @@ local format_target = function(target)
end end
end end
local escape = function(text) local function escape(text)
text = text:gsub('\\', '\\\\') text = text:gsub('\\', '\\\\')
text = text:gsub('\n', '\\n') text = text:gsub('\n', '\\n')
text = text:gsub('\t', '\\t') text = text:gsub('\t', '\\t')
@ -71,7 +71,7 @@ local drua = {
PORT = 4567 PORT = 4567
} }
drua.send = function(command, do_receive) function drua.send(command, do_receive)
local s = SOCKET.connect(drua.IP, drua.PORT) local s = SOCKET.connect(drua.IP, drua.PORT)
assert(s, '\nUnable to connect to tg session.') assert(s, '\nUnable to connect to tg session.')
s:send(command..'\n') s:send(command..'\n')
@ -84,7 +84,7 @@ drua.send = function(command, do_receive)
return output return output
end end
drua.message = function(target, text) function drua.message(target, text)
target = format_target(target) target = format_target(target)
text = escape(text) text = escape(text)
local command = 'msg %s "%s"' local command = 'msg %s "%s"'
@ -92,14 +92,14 @@ drua.message = function(target, text)
return drua.send(command) return drua.send(command)
end end
drua.send_photo = function(target, photo) function drua.send_photo(target, photo)
target = format_target(target) target = format_target(target)
local command = 'send_photo %s %s' local command = 'send_photo %s %s'
command = command:format(target, photo) command = command:format(target, photo)
return drua.send(command) return drua.send(command)
end end
drua.add_user = function(chat, target) function drua.add_user(chat, target)
local a local a
chat, a = format_target(chat) chat, a = format_target(chat)
target = format_target(target) target = format_target(target)
@ -107,7 +107,7 @@ drua.add_user = function(chat, target)
return drua.send(command) return drua.send(command)
end end
drua.kick_user = function(chat, target) function drua.kick_user(chat, target)
-- Get the group info so tg will recognize the target. -- Get the group info so tg will recognize the target.
drua.get_info(chat) drua.get_info(chat)
local a local a
@ -117,21 +117,21 @@ drua.kick_user = function(chat, target)
return drua.send(command) return drua.send(command)
end end
drua.rename_chat = function(chat, name) function drua.rename_chat(chat, name)
local a local a
chat, a = format_target(chat) chat, a = format_target(chat)
local command = comtab.rename[a]:format(chat, name) local command = comtab.rename[a]:format(chat, name)
return drua.send(command) return drua.send(command)
end end
drua.export_link = function(chat) function drua.export_link(chat)
local a local a
chat, a = format_target(chat) chat, a = format_target(chat)
local command = comtab.link[a]:format(chat) local command = comtab.link[a]:format(chat)
return drua.send(command, true) return drua.send(command, true)
end end
drua.get_photo = function(chat) function drua.get_photo(chat)
local a local a
chat, a = format_target(chat) chat, a = format_target(chat)
local command = comtab.photo_get[a]:format(chat) local command = comtab.photo_get[a]:format(chat)
@ -143,21 +143,21 @@ drua.get_photo = function(chat)
end end
end end
drua.set_photo = function(chat, photo) function drua.set_photo(chat, photo)
local a local a
chat, a = format_target(chat) chat, a = format_target(chat)
local command = comtab.photo_set[a]:format(chat, photo) local command = comtab.photo_set[a]:format(chat, photo)
return drua.send(command) return drua.send(command)
end end
drua.get_info = function(target) function drua.get_info(target)
local a local a
target, a = format_target(target) target, a = format_target(target)
local command = comtab.info[a]:format(target) local command = comtab.info[a]:format(target)
return drua.send(command, true) return drua.send(command, true)
end end
drua.channel_set_admin = function(chat, user, rank) function drua.channel_set_admin(chat, user, rank)
chat = format_target(chat) chat = format_target(chat)
user = format_target(user) user = format_target(user)
local command = 'channel_set_admin %s %s %s' local command = 'channel_set_admin %s %s %s'
@ -165,7 +165,7 @@ drua.channel_set_admin = function(chat, user, rank)
return drua.send(command) return drua.send(command)
end end
drua.channel_set_about = function(chat, text) function drua.channel_set_about(chat, text)
chat = format_target(chat) chat = format_target(chat)
text = escape(text) text = escape(text)
local command = 'channel_set_about %s "%s"' local command = 'channel_set_about %s "%s"'
@ -173,11 +173,11 @@ drua.channel_set_about = function(chat, text)
return drua.send(command) return drua.send(command)
end end
drua.block = function(user) function drua.block(user)
return drua.send('block_user user#' .. user) return drua.send('block_user user#' .. user)
end end
drua.unblock = function(user) function drua.unblock(user)
return drua.send('unblock_user user#' .. user) return drua.send('unblock_user user#' .. user)
end end

View File

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

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 = {} local data = {}
for k,v in pairs(userdata) do for k,v in pairs(userdata) do
table.insert(data, string.format( 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(k),
utilities.html_escape(v) utilities.html_escape(v)
)) ))

View File

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

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 reactions = {}
local utilities = require('otouto.utilities') local utilities = require('otouto.utilities')
@ -13,15 +5,13 @@ local utilities = require('otouto.utilities')
reactions.command = 'reactions' reactions.command = 'reactions'
reactions.doc = 'Returns a list of "reaction" emoticon commands.' reactions.doc = 'Returns a list of "reaction" emoticon commands.'
local help
function reactions:init(config) function reactions:init(config)
-- Generate a "help" message triggered by "/reactions". -- Generate a command list message triggered by "/reactions".
help = 'Reactions:\n' reactions.help = 'Reactions:\n'
reactions.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('reactions').table reactions.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('reactions').table
local username = self.info.username:lower() local username = self.info.username:lower()
for trigger, reaction in pairs(config.reactions) do for trigger, reaction in pairs(config.reactions) do
help = help .. '' .. config.cmd_pat .. trigger .. ': ' .. reaction .. '\n' 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)
table.insert(reactions.triggers, '^'..config.cmd_pat..trigger..'@'..username) table.insert(reactions.triggers, '^'..config.cmd_pat..trigger..'@'..username)
table.insert(reactions.triggers, config.cmd_pat..trigger..'$') table.insert(reactions.triggers, config.cmd_pat..trigger..'$')
@ -35,12 +25,12 @@ end
function reactions:action(msg, config) function reactions:action(msg, config)
if string.match(msg.text_lower, config.cmd_pat..'reactions') then 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 return
end end
for trigger,reaction in pairs(config.reactions) do for trigger,reaction in pairs(config.reactions) do
if string.match(msg.text_lower, config.cmd_pat..trigger) then 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 return
end end
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' Aliases: ]] .. config.cmd_pat .. 'r, /r/subreddit'
end end
local format_results = function(posts) local function format_results(posts)
local output = '' local output = ''
for _,v in ipairs(posts) do for _,v in ipairs(posts) do
local post = v.data 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 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> remind.doc = config.cmd_pat .. [[remind <duration> <message>
Repeats a message after a duration of time, in minutes. 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.]] 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.]]