administration.lua: kicking via tg is much faster than kicking via API
control.lua: added /script command
This commit is contained in:
parent
64621a640e
commit
68c1ae226c
15
bindings.lua
15
bindings.lua
@ -187,11 +187,18 @@ function bindings:sendPhotoID(chat_id, file_id, caption, reply_to_message_id, di
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function bindings.curlRequest(curl_command)
|
function bindings.curlRequest(curl_command, give_output)
|
||||||
-- Use at your own risk. Will not check for success.
|
if give_output then
|
||||||
|
local s = io.popen(curl_command):read('*all')
|
||||||
|
local tab = JSON.encode(s)
|
||||||
|
if not tab then return false end
|
||||||
|
if not tab.ok then
|
||||||
|
return false, tab.description
|
||||||
|
end
|
||||||
|
return tab
|
||||||
|
else
|
||||||
io.popen(curl_command)
|
io.popen(curl_command)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function bindings:sendPhoto(chat_id, photo, caption, reply_to_message_id, disable_notification)
|
function bindings:sendPhoto(chat_id, photo, caption, reply_to_message_id, disable_notification)
|
||||||
|
5
bot.lua
5
bot.lua
@ -19,7 +19,10 @@ function bot:init() -- The function run when the bot is started or reloaded.
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Fetch bot information. Try until it succeeds.
|
-- Fetch bot information. Try until it succeeds.
|
||||||
repeat self.info = bindings.getMe(self) until self.info
|
repeat
|
||||||
|
print('Fetching bot information...')
|
||||||
|
self.info = bindings.getMe(self)
|
||||||
|
until self.info
|
||||||
self.info = self.info.result
|
self.info = self.info.result
|
||||||
|
|
||||||
-- Load the "database"! ;)
|
-- Load the "database"! ;)
|
||||||
|
@ -242,9 +242,7 @@ function administration:update_desc(chat)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function administration:kick_user(chat, target, reason)
|
function administration:kick_user(chat, target, reason)
|
||||||
if not bindings.kickChatMember(self, chat, target) then
|
|
||||||
drua.kick_user(chat, target)
|
drua.kick_user(chat, target)
|
||||||
end
|
|
||||||
utilities.handle_exception(self, target..' kicked from '..chat, reason)
|
utilities.handle_exception(self, target..' kicked from '..chat, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1037,11 +1035,11 @@ function administration.init_command(self_)
|
|||||||
else
|
else
|
||||||
administration.kick_user(self, msg.chat.id, target.id, 'hammered by '..msg.from.id)
|
administration.kick_user(self, msg.chat.id, target.id, 'hammered by '..msg.from.id)
|
||||||
self.database.blacklist[target.id_str] = true
|
self.database.blacklist[target.id_str] = true
|
||||||
--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
|
||||||
--administration.kick_user(self, k, target.id)
|
drua.kick_user(k, target.id)
|
||||||
--end
|
end
|
||||||
--end
|
end
|
||||||
local output = target.name .. ' has been globally banned.'
|
local output = target.name .. ' has been globally banned.'
|
||||||
if group.flags[6] == true then
|
if group.flags[6] == true then
|
||||||
group.bans[target.id_str] = true
|
group.bans[target.id_str] = true
|
||||||
@ -1114,6 +1112,7 @@ function administration.init_command(self_)
|
|||||||
end
|
end
|
||||||
table.insert(self.database.administration.activity, msg.chat.id_str)
|
table.insert(self.database.administration.activity, msg.chat.id_str)
|
||||||
bindings.sendReply(self, msg, 'I am now administrating this group.')
|
bindings.sendReply(self, msg, 'I am now administrating this group.')
|
||||||
|
drua.channel_set_admin(msg.chat.id, self.info.id, 2)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
function control:init()
|
function control:init()
|
||||||
control.triggers = utilities.triggers(self.info.username):t('reload'):t('halt').table
|
control.triggers = utilities.triggers(self.info.username):t('reload'):t('halt').table
|
||||||
|
table.insert(control.triggers, '^/script')
|
||||||
end
|
end
|
||||||
|
|
||||||
function control:action(msg)
|
function control:action(msg)
|
||||||
@ -30,6 +31,18 @@ function control:action(msg)
|
|||||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
||||||
self.is_started = false
|
self.is_started = false
|
||||||
bindings.sendReply(self, msg, 'Stopping bot!')
|
bindings.sendReply(self, msg, 'Stopping bot!')
|
||||||
|
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'script') then
|
||||||
|
local input = msg.text:match('^'..utilities.INVOCATION_PATTERN..'script\n(.+)')
|
||||||
|
if not input then
|
||||||
|
bindings.sendReply(self, msg, 'usage: ```\n/script\n/command <arg>\n...\n```', true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
input = input .. '\n'
|
||||||
|
for command in input:gmatch('(.-)\n') do
|
||||||
|
command = utilities.trim(command)
|
||||||
|
msg.text = command
|
||||||
|
bot.on_msg_receive(self, msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -144,14 +144,12 @@ function utilities.build_name(first, last)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function utilities:resolve_username(input)
|
function utilities:resolve_username(input)
|
||||||
|
|
||||||
input = input:gsub('^@', '')
|
input = input:gsub('^@', '')
|
||||||
for _,v in pairs(self.database.users) do
|
for _,v in pairs(self.database.users) do
|
||||||
if v.username and v.username:lower() == input:lower() then
|
if v.username and v.username:lower() == input:lower() then
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function utilities:user_from_message(msg, no_extra)
|
function utilities:user_from_message(msg, no_extra)
|
||||||
|
Reference in New Issue
Block a user