parent
acc7046d64
commit
f9a4bc8803
@ -9,6 +9,12 @@
|
|||||||
drua.PORT = 4567
|
drua.PORT = 4567
|
||||||
drua.message(chat_id, text)
|
drua.message(chat_id, text)
|
||||||
|
|
||||||
|
To run multiple commands on the same TCP session:
|
||||||
|
s = drua.sopen()
|
||||||
|
drua.message(chat_id, text, s)
|
||||||
|
drua.send_photo(chat_id, filename, s)
|
||||||
|
s:close()
|
||||||
|
|
||||||
Copyright 2015-2016 Juan Potato
|
Copyright 2015-2016 Juan Potato
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -69,71 +75,86 @@ local drua = {
|
|||||||
PORT = 4567
|
PORT = 4567
|
||||||
}
|
}
|
||||||
|
|
||||||
function drua.send(command, do_receive)
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
function drua.simple(s, command, do_receive)
|
||||||
s:send(command..'\n')
|
s:send(command..'\n')
|
||||||
local output
|
local output
|
||||||
if do_receive then
|
if do_receive then
|
||||||
output = string.match(s:receive('*l'), 'ANSWER (%d+)')
|
output = string.match(s:receive('*l'), 'ANSWER (%d+)')
|
||||||
output = s:receive(tonumber(output)):gsub('\n$', '')
|
output = s:receive(tonumber(output)):gsub('\n$', '')
|
||||||
|
s:receive('*l')
|
||||||
end
|
end
|
||||||
s:close()
|
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.message(target, text)
|
function drua.send(s, command, do_receive)
|
||||||
|
if s then
|
||||||
|
return drua.simple(s, command, do_receive)
|
||||||
|
else
|
||||||
|
s = drua.sopen()
|
||||||
|
local output = drua.simple(s, command, do_receive)
|
||||||
|
s:close()
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function drua.message(target, text, s)
|
||||||
target = format_target(target)
|
target = format_target(target)
|
||||||
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(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.send_photo(target, photo)
|
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(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.add_user(chat, target)
|
function drua.add_user(chat, target, 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.add[a]:format(chat, target)
|
local command = comtab.add[a]:format(chat, target)
|
||||||
return drua.send(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.kick_user(chat, target)
|
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)
|
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(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.rename_chat(chat, name)
|
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(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.export_link(chat)
|
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(command, true)
|
return drua.send(s, command, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.get_photo(chat)
|
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(command, true)
|
local output = drua.send(s, command, true)
|
||||||
if output:match('FAIL') then
|
if output:match('FAIL') then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
@ -141,42 +162,42 @@ function drua.get_photo(chat)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.set_photo(chat, photo)
|
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(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.get_info(target)
|
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(command, true)
|
return drua.send(s, command, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.channel_set_admin(chat, user, rank)
|
function drua.channel_set_admin(chat, user, rank, s)
|
||||||
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'
|
||||||
command = command:format(chat, user, rank)
|
command = command:format(chat, user, rank)
|
||||||
return drua.send(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.channel_set_about(chat, text)
|
function drua.channel_set_about(chat, text, s)
|
||||||
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"'
|
||||||
command = command:format(chat, text)
|
command = command:format(chat, text)
|
||||||
return drua.send(command)
|
return drua.send(s, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.block(user)
|
function drua.block(user, s)
|
||||||
return drua.send('block_user user#' .. user)
|
return drua.send(s, 'block_user user#' .. user)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drua.unblock(user)
|
function drua.unblock(user, s)
|
||||||
return drua.send('unblock_user user#' .. user)
|
return drua.send(s, 'unblock_user user#' .. user)
|
||||||
end
|
end
|
||||||
|
|
||||||
return drua
|
return drua
|
||||||
|
@ -340,8 +340,8 @@ function administration:update_desc(chat, config)
|
|||||||
drua.channel_set_about(chat, desc)
|
drua.channel_set_about(chat, desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
function administration:kick_user(chat, target, reason, config)
|
function administration:kick_user(chat, target, reason, config, s)
|
||||||
drua.kick_user(chat, target)
|
drua.kick_user(chat, target, s)
|
||||||
local victim = target
|
local victim = target
|
||||||
if self.database.users[tostring(target)] then
|
if self.database.users[tostring(target)] then
|
||||||
victim = utilities.build_name(
|
victim = utilities.build_name(
|
||||||
@ -812,6 +812,7 @@ function administration.init_command(self_, config_)
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -819,12 +820,13 @@ function administration.init_command(self_, config_)
|
|||||||
output = output .. target.name .. ' is too privileged to be kicked.\n'
|
output = output .. target.name .. ' is too privileged to be kicked.\n'
|
||||||
else
|
else
|
||||||
output = output .. target.name .. ' has been kicked.\n'
|
output = output .. target.name .. ' has been kicked.\n'
|
||||||
administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config)
|
administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config, s)
|
||||||
if msg.chat.type == 'supergroup' then
|
if msg.chat.type == 'supergroup' then
|
||||||
bindings.unbanChatMember{ chat_id = msg.chat.id, user_id = target.id }
|
bindings.unbanChatMember{ chat_id = msg.chat.id, user_id = target.id }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
@ -844,6 +846,7 @@ function administration.init_command(self_, config_)
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -853,11 +856,12 @@ function administration.init_command(self_, config_)
|
|||||||
output = output .. target.name .. ' is too privileged to be banned.\n'
|
output = output .. target.name .. ' is too privileged to be banned.\n'
|
||||||
else
|
else
|
||||||
output = output .. target.name .. ' has been banned.\n'
|
output = output .. target.name .. ' has been banned.\n'
|
||||||
administration.kick_user(self, msg.chat.id, target.id, 'banned by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config)
|
administration.kick_user(self, msg.chat.id, target.id, 'banned by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config, s)
|
||||||
group.mods[target.id_str] = nil
|
group.mods[target.id_str] = nil
|
||||||
group.bans[target.id_str] = true
|
group.bans[target.id_str] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
@ -1115,7 +1119,11 @@ function administration.init_command(self_, config_)
|
|||||||
output = 'Not a valid message type or number.'
|
output = 'Not a valid message type or number.'
|
||||||
elseif key == 'autoban' then
|
elseif key == 'autoban' then
|
||||||
group.autoban = tonumber(val)
|
group.autoban = tonumber(val)
|
||||||
output = 'Users will now be autobanned after *' .. val .. '* autokicks.'
|
output = string.format(
|
||||||
|
'Users will now be automatically banned after *%s* automatic kick%s.',
|
||||||
|
val,
|
||||||
|
group.autoban == 1 and '' or 's'
|
||||||
|
)
|
||||||
else
|
else
|
||||||
group.antiflood[key] = tonumber(val)
|
group.antiflood[key] = tonumber(val)
|
||||||
output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.'
|
output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.'
|
||||||
@ -1130,11 +1138,13 @@ function administration.init_command(self_, config_)
|
|||||||
usage: `%santiflood <type> <i>`
|
usage: `%santiflood <type> <i>`
|
||||||
example: `%santiflood text 5`
|
example: `%santiflood text 5`
|
||||||
Use this command to configure the point values for each message type. When a user reaches 100 points, he is kicked. The points are reset each minute. The current values are:
|
Use this command to configure the point values for each message type. When a user reaches 100 points, he is kicked. The points are reset each minute. The current values are:
|
||||||
%s
|
%sUsers are automatically banned after *%s* automatic kick%s.
|
||||||
]],
|
]],
|
||||||
config.cmd_pat,
|
config.cmd_pat,
|
||||||
config.cmd_pat,
|
config.cmd_pat,
|
||||||
output
|
output,
|
||||||
|
group.autoban,
|
||||||
|
group.autoban == 1 and '' or 's'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
utilities.send_message(msg.chat.id, output, true, msg.message_id, true)
|
utilities.send_message(msg.chat.id, output, true, msg.message_id, true)
|
||||||
@ -1154,6 +1164,7 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -1168,11 +1179,12 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
if group.grouptype == 'supergroup' then
|
if group.grouptype == 'supergroup' then
|
||||||
local chat_member = bindings.getChatMember{ chat_id = msg.chat.id, user_id = target.id }
|
local chat_member = bindings.getChatMember{ chat_id = msg.chat.id, user_id = target.id }
|
||||||
if chat_member and chat_member.result.status == 'member' then
|
if chat_member and chat_member.result.status == 'member' then
|
||||||
drua.channel_set_admin(msg.chat.id, target.id, 2)
|
drua.channel_set_admin(msg.chat.id, target.id, 2, s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
@ -1192,6 +1204,7 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -1203,10 +1216,11 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
group.mods[target.id_str] = nil
|
group.mods[target.id_str] = nil
|
||||||
end
|
end
|
||||||
if group.grouptype == 'supergroup' then
|
if group.grouptype == 'supergroup' then
|
||||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
drua.channel_set_admin(msg.chat.id, target.id, 0, s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
@ -1295,6 +1309,7 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -1307,12 +1322,10 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
local reason = 'hammered by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']'
|
local reason = 'hammered by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']'
|
||||||
administration.kick_user(self, msg.chat.id, target.id, reason, config)
|
administration.kick_user(self, msg.chat.id, target.id, reason, config)
|
||||||
end
|
end
|
||||||
if #targets == 1 then
|
|
||||||
for k,v in pairs(self.database.administration.groups) do
|
for k,v in pairs(self.database.administration.groups) do
|
||||||
if not v.flags[6] then
|
if not v.flags[6] then
|
||||||
v.mods[target.id_str] = nil
|
v.mods[target.id_str] = nil
|
||||||
bindings.kickChatMember{chat_id = k, user_id = target.id}
|
drua.kick_user(k, target.id, s)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.database.administration.globalbans[target.id_str] = true
|
self.database.administration.globalbans[target.id_str] = true
|
||||||
@ -1325,6 +1338,7 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
@ -1405,6 +1419,7 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
local targets = administration.get_targets(self, msg, config)
|
local targets = administration.get_targets(self, msg, config)
|
||||||
if targets then
|
if targets then
|
||||||
local output = ''
|
local output = ''
|
||||||
|
local s = drua.sopen()
|
||||||
for _, target in ipairs(targets) do
|
for _, target in ipairs(targets) do
|
||||||
if target.err then
|
if target.err then
|
||||||
output = output .. target.err .. '\n'
|
output = output .. target.err .. '\n'
|
||||||
@ -1413,13 +1428,14 @@ Use this command to configure the point values for each message type. When a use
|
|||||||
else
|
else
|
||||||
for chat_id, group in pairs(self.database.administration.groups) do
|
for chat_id, group in pairs(self.database.administration.groups) do
|
||||||
if group.grouptype == 'supergroup' then
|
if group.grouptype == 'supergroup' then
|
||||||
drua.channel_set_admin(chat_id, target.id, 0)
|
drua.channel_set_admin(chat_id, target.id, 0, s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.database.administration.admins[target.id_str] = nil
|
self.database.administration.admins[target.id_str] = nil
|
||||||
output = output .. target.name .. ' is no longer an administrator.\n'
|
output = output .. target.name .. ' is no longer an administrator.\n'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s:close()
|
||||||
utilities.send_reply(msg, output)
|
utilities.send_reply(msg, output)
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
utilities.send_reply(msg, 'Please specify a user or users via reply, username, or ID.')
|
||||||
|
Reference in New Issue
Block a user