more drua stuff
This commit is contained in:
parent
f9a4bc8803
commit
1e99a9a1f3
@ -36,7 +36,7 @@
|
|||||||
IN THE SOFTWARE.
|
IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local SOCKET = require('socket')
|
local socket = require('socket')
|
||||||
|
|
||||||
local comtab = {
|
local comtab = {
|
||||||
add = { 'chat_add_user %s %s', 'channel_invite %s %s' },
|
add = { 'chat_add_user %s %s', 'channel_invite %s %s' },
|
||||||
@ -76,12 +76,12 @@ local drua = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drua.sopen()
|
function drua.sopen()
|
||||||
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.')
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.simple(s, command, do_receive)
|
function drua.simple(command, do_receive, s)
|
||||||
s:send(command..'\n')
|
s:send(command..'\n')
|
||||||
local output
|
local output
|
||||||
if do_receive then
|
if do_receive then
|
||||||
@ -92,12 +92,12 @@ function drua.simple(s, command, do_receive)
|
|||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.send(s, command, do_receive)
|
function drua.send(command, do_receive, s)
|
||||||
if s then
|
if s then
|
||||||
return drua.simple(s, command, do_receive)
|
return drua.simple(command, do_receive, s)
|
||||||
else
|
else
|
||||||
s = drua.sopen()
|
s = drua.sopen()
|
||||||
local output = drua.simple(s, command, do_receive)
|
local output = drua.simple(command, do_receive, s)
|
||||||
s:close()
|
s:close()
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
@ -108,14 +108,14 @@ function drua.message(target, text, s)
|
|||||||
text = escape(text)
|
text = escape(text)
|
||||||
local command = 'msg %s "%s"'
|
local command = 'msg %s "%s"'
|
||||||
command = command:format(target, text)
|
command = command:format(target, text)
|
||||||
return drua.send(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.send_photo(target, photo, s)
|
function drua.send_photo(target, photo, s)
|
||||||
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(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.add_user(chat, target, s)
|
function drua.add_user(chat, target, s)
|
||||||
@ -123,38 +123,38 @@ function drua.add_user(chat, target, s)
|
|||||||
chat, a = format_target(chat)
|
chat, a = format_target(chat)
|
||||||
target = format_target(target)
|
target = format_target(target)
|
||||||
local command = comtab.add[a]:format(chat, target)
|
local command = comtab.add[a]:format(chat, target)
|
||||||
return drua.send(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.kick_user(chat, target, s)
|
function drua.kick_user(chat, target, s)
|
||||||
-- Get the group info so tg will recognize the target.
|
-- Get the group info so tg will recognize the target.
|
||||||
drua.get_info(chat, s)
|
drua.get_info(chat, _, s)
|
||||||
local a
|
local a
|
||||||
chat, a = format_target(chat)
|
chat, a = format_target(chat)
|
||||||
target = format_target(target)
|
target = format_target(target)
|
||||||
local command = comtab.kick[a]:format(chat, target)
|
local command = comtab.kick[a]:format(chat, target)
|
||||||
return drua.send(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.rename_chat(chat, name, s)
|
function drua.rename_chat(chat, name, s)
|
||||||
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(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.export_link(chat, s)
|
function drua.export_link(chat, s)
|
||||||
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(s, command, true)
|
return drua.send(command, true, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.get_photo(chat, s)
|
function drua.get_photo(chat, s)
|
||||||
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)
|
||||||
local output = drua.send(s, command, true)
|
local output = drua.send(command, true, s)
|
||||||
if output:match('FAIL') then
|
if output:match('FAIL') then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@ -166,14 +166,14 @@ function drua.set_photo(chat, photo, s)
|
|||||||
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(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.get_info(target, s)
|
function drua.get_info(target, s)
|
||||||
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(s, command, true)
|
return drua.send(command, true, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.channel_set_admin(chat, user, rank, s)
|
function drua.channel_set_admin(chat, user, rank, s)
|
||||||
@ -181,7 +181,7 @@ function drua.channel_set_admin(chat, user, rank, s)
|
|||||||
user = format_target(user)
|
user = format_target(user)
|
||||||
local command = 'channel_set_admin %s %s %s'
|
local command = 'channel_set_admin %s %s %s'
|
||||||
command = command:format(chat, user, rank)
|
command = command:format(chat, user, rank)
|
||||||
return drua.send(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.channel_set_about(chat, text, s)
|
function drua.channel_set_about(chat, text, s)
|
||||||
@ -189,15 +189,15 @@ function drua.channel_set_about(chat, text, s)
|
|||||||
text = escape(text)
|
text = escape(text)
|
||||||
local command = 'channel_set_about %s "%s"'
|
local command = 'channel_set_about %s "%s"'
|
||||||
command = command:format(chat, text)
|
command = command:format(chat, text)
|
||||||
return drua.send(s, command)
|
return drua.send(command, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.block(user, s)
|
function drua.block(user, s)
|
||||||
return drua.send(s, 'block_user user#' .. user)
|
return drua.send('block_user user#' .. user, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.unblock(user, s)
|
function drua.unblock(user, s)
|
||||||
return drua.send(s, 'unblock_user user#' .. user)
|
return drua.send('unblock_user user#' .. user, _, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
return drua
|
return drua
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local utilities = require('otouto.utilities')
|
local utilities = require('otouto.utilities')
|
||||||
|
local drua = require('otouto.drua-tg')
|
||||||
|
|
||||||
local blacklist = {}
|
local blacklist = {}
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ function blacklist:action(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
if msg.text:match('^'..config.cmd_pat..'blacklist') then
|
if msg.text:match('^'..config.cmd_pat..'blacklist') then
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
@ -69,7 +71,7 @@ function blacklist:action(msg, config)
|
|||||||
self.database.blacklist[target.id_str] = true
|
self.database.blacklist[target.id_str] = true
|
||||||
output = output .. target.name .. ' is now blacklisted.\n'
|
output = output .. target.name .. ' is now blacklisted.\n'
|
||||||
if config.drua_block_on_blacklist and target.id > 0 then
|
if config.drua_block_on_blacklist and target.id > 0 then
|
||||||
require('otouto.drua-tg').block(target.id)
|
drua.block(target.id, s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -83,11 +85,12 @@ function blacklist:action(msg, config)
|
|||||||
self.database.blacklist[target.id_str] = nil
|
self.database.blacklist[target.id_str] = nil
|
||||||
output = output .. target.name .. ' is no longer blacklisted.\n'
|
output = output .. target.name .. ' is no longer blacklisted.\n'
|
||||||
if config.drua_block_on_blacklist and target.id > 0 then
|
if config.drua_block_on_blacklist and target.id > 0 then
|
||||||
require('otouto.drua-tg').unblock(target.id)
|
drua.unblock(target.id, s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user