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
|
||||
|
||||
function bindings.curlRequest(curl_command)
|
||||
-- Use at your own risk. Will not check for success.
|
||||
|
||||
function bindings.curlRequest(curl_command, give_output)
|
||||
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)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
|
||||
-- Load the "database"! ;)
|
||||
|
@ -242,9 +242,7 @@ function administration:update_desc(chat)
|
||||
end
|
||||
|
||||
function administration:kick_user(chat, target, reason)
|
||||
if not bindings.kickChatMember(self, chat, target) then
|
||||
drua.kick_user(chat, target)
|
||||
end
|
||||
utilities.handle_exception(self, target..' kicked from '..chat, reason)
|
||||
end
|
||||
|
||||
@ -1037,11 +1035,11 @@ function administration.init_command(self_)
|
||||
else
|
||||
administration.kick_user(self, msg.chat.id, target.id, 'hammered by '..msg.from.id)
|
||||
self.database.blacklist[target.id_str] = true
|
||||
--for k,v in pairs(self.database.administration.groups) do
|
||||
--if not v.flags[6] then
|
||||
--administration.kick_user(self, k, target.id)
|
||||
--end
|
||||
--end
|
||||
for k,v in pairs(self.database.administration.groups) do
|
||||
if not v.flags[6] then
|
||||
drua.kick_user(k, target.id)
|
||||
end
|
||||
end
|
||||
local output = target.name .. ' has been globally banned.'
|
||||
if group.flags[6] == true then
|
||||
group.bans[target.id_str] = true
|
||||
@ -1114,6 +1112,7 @@ function administration.init_command(self_)
|
||||
end
|
||||
table.insert(self.database.administration.activity, msg.chat.id_str)
|
||||
bindings.sendReply(self, msg, 'I am now administrating this group.')
|
||||
drua.channel_set_admin(msg.chat.id, self.info.id, 2)
|
||||
end
|
||||
},
|
||||
|
||||
|
@ -6,6 +6,7 @@ local utilities = require('utilities')
|
||||
|
||||
function control:init()
|
||||
control.triggers = utilities.triggers(self.info.username):t('reload'):t('halt').table
|
||||
table.insert(control.triggers, '^/script')
|
||||
end
|
||||
|
||||
function control:action(msg)
|
||||
@ -30,6 +31,18 @@ function control:action(msg)
|
||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
||||
self.is_started = false
|
||||
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
|
||||
|
@ -144,14 +144,12 @@ function utilities.build_name(first, last)
|
||||
end
|
||||
|
||||
function utilities:resolve_username(input)
|
||||
|
||||
input = input:gsub('^@', '')
|
||||
for _,v in pairs(self.database.users) do
|
||||
if v.username and v.username:lower() == input:lower() then
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function utilities:user_from_message(msg, no_extra)
|
||||
|
Reference in New Issue
Block a user