good stuff
README.md: Greatly updated. Will do more in future. administration.lua: Administrators will now be promoted to group admins upon joining an administrated group. drua-tg: Squashed all luacheck warnings. chatter.lua: Mostly rewritten; things actually make sense now. xkcd.lua: Slight styling change. patterns.lua: Squashed a warning.
This commit is contained in:
@ -272,8 +272,7 @@ function administration.init_command(self_)
|
||||
|
||||
action = function(self, msg, group)
|
||||
|
||||
local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
|
||||
local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
local user = {}
|
||||
|
||||
if rank < 2 then
|
||||
@ -343,27 +342,27 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
end
|
||||
|
||||
local new_user = user
|
||||
local new_rank = rank
|
||||
|
||||
if msg.new_chat_participant then
|
||||
|
||||
-- I hate typing this out.
|
||||
local noob = msg.new_chat_participant
|
||||
|
||||
-- We'll make a new table for the new guy, unless he's also
|
||||
-- the original guy.
|
||||
if msg.new_chat_participant.id ~= msg.from.id then
|
||||
new_user = {}
|
||||
new_rank = administration.get_rank(self,noob.id, msg.chat.id)
|
||||
end
|
||||
|
||||
-- I hate typing this out.
|
||||
local noob = msg.new_chat_participant
|
||||
|
||||
if administration.get_rank(self, msg.new_chat_participant.id, msg.chat.id) < 2 then
|
||||
|
||||
-- banned
|
||||
if administration.get_rank(self, noob.id, msg.chat.id) == 0 then
|
||||
new_user.do_kick = true
|
||||
new_user.dont_unban = true
|
||||
new_user.reason = 'banned'
|
||||
new_user.output = 'Sorry, you are banned from ' .. msg.chat.title .. '.'
|
||||
elseif group.flags[3] and ( -- antisquig++
|
||||
if new_rank == 0 then
|
||||
new_user.do_kick = true
|
||||
new_user.dont_unban = true
|
||||
new_user.reason = 'banned'
|
||||
new_user.output = 'Sorry, you are banned from ' .. msg.chat.title .. '.'
|
||||
elseif new_rank == 1 then
|
||||
if group.flags[3] and ( -- antisquig++
|
||||
noob.name:match(utilities.char.arabic)
|
||||
or noob.name:match(utilities.char.rtl_override)
|
||||
or noob.name:match(utilities.char.rtl_mark)
|
||||
@ -371,11 +370,20 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
new_user.do_kick = true
|
||||
new_user.reason = 'antisquig++'
|
||||
new_user.output = administration.flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
elseif group.flags[4] and noob.username and noob.username:match('bot') and rank < 2 then
|
||||
elseif ( -- antibot
|
||||
group.flags[4]
|
||||
and noob.username
|
||||
and noob.username:match('bot')
|
||||
and rank < 2
|
||||
) then
|
||||
new_user.do_kick = true
|
||||
new_user.reason = 'antibot'
|
||||
end
|
||||
|
||||
else
|
||||
-- Make the new user a group admin if he's a mod or higher.
|
||||
if msg.chat.type == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, msg.new_chat_participant.id, 2)
|
||||
end
|
||||
end
|
||||
|
||||
elseif msg.new_chat_title then
|
||||
@ -1165,11 +1173,18 @@ local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
|
||||
local target = administration.get_target(self, msg)
|
||||
if target.err then
|
||||
utilities.send_reply(self, msg, target.err)
|
||||
elseif target.rank ~= 4 then
|
||||
utilities.send_reply(self, msg, target.name .. ' is not an administrator.')
|
||||
else
|
||||
self.database.administration.admins[target.id_str] = nil
|
||||
utilities.send_reply(self, msg, target.name .. ' is no longer an administrator.')
|
||||
for chat_id, group in pairs(self.database.administration.groups) do
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(chat_id, target.id, 0)
|
||||
end
|
||||
end
|
||||
if target.rank ~= 4 then
|
||||
utilities.send_reply(self, msg, target.name .. ' is not an administrator.')
|
||||
else
|
||||
self.database.administration.admins[target.id_str] = nil
|
||||
utilities.send_reply(self, msg, target.name .. ' is no longer an administrator.')
|
||||
end
|
||||
end
|
||||
end
|
||||
},
|
||||
|
@ -16,42 +16,38 @@ function chatter:init()
|
||||
end
|
||||
|
||||
chatter.triggers = {
|
||||
'',
|
||||
'^' .. self.info.first_name .. ',',
|
||||
'^@' .. self.info.username .. ','
|
||||
''
|
||||
}
|
||||
end
|
||||
|
||||
chatter.base_url = 'http://%sapi.simsimi.com/request.p?key=%s&lc=%s&ft=1.0&text=%s'
|
||||
|
||||
function chatter:action(msg)
|
||||
|
||||
if msg.text == '' then return end
|
||||
if msg.text == '' then return true end
|
||||
|
||||
-- This is awkward, but if you have a better way, please share.
|
||||
if msg.text_lower:match('^' .. self.info.first_name .. ',')
|
||||
or msg.text_lower:match('^@' .. self.info.username .. ',') then
|
||||
elseif msg.text:match('^/') then
|
||||
return true
|
||||
-- Uncomment the following line for Al Gore-like reply chatter.
|
||||
-- elseif msg.reply_to_message and msg.reply_to_message.from.id == bot.id then
|
||||
elseif msg.from.id == msg.chat.id then
|
||||
else
|
||||
if (
|
||||
not (
|
||||
msg.text_lower:match('^'..self.info.first_name:lower()..',')
|
||||
or msg.text_lower:match('^@'..self.info.username:lower()..',')
|
||||
or msg.from.id == msg.chat.id
|
||||
--Uncomment the following line for Al Gore-like conversation.
|
||||
--or (msg.reply_to_message and msg.reply_to_message.from.id == self.info.id)
|
||||
)
|
||||
or msg.text:match('^/')
|
||||
or msg.text == ''
|
||||
) then
|
||||
return true
|
||||
end
|
||||
|
||||
bindings.sendChatAction(self, { action = 'typing' } )
|
||||
|
||||
local input = msg.text_lower
|
||||
input = input:gsub(self.info.first_name, 'simsimi')
|
||||
local input = msg.text_lower:gsub(self.info.first_name, 'simsimi')
|
||||
input = input:gsub('@'..self.info.username, 'simsimi')
|
||||
|
||||
local sandbox
|
||||
if self.config.simsimi_trial then
|
||||
sandbox = 'sandbox.'
|
||||
else
|
||||
sandbox = '' -- NO Sandbox
|
||||
end
|
||||
local sandbox = self.config.simsimi_trial and 'sandbox.' or ''
|
||||
|
||||
local url = 'http://' ..sandbox.. 'api.simsimi.com/request.p?key=' ..self.config.simsimi_key.. '&lc=' ..self.config.lang.. '&ft=1.0&text=' .. URL.escape(input)
|
||||
local url = chatter.base_url:format(sandbox, self.config.simsimi_key, self.config.lang, URL.escape(input))
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
if res ~= 200 then
|
||||
@ -60,31 +56,22 @@ function chatter:action(msg)
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if not jdat.response then
|
||||
if not jdat.response or jdat.response:match('^I HAVE NO RESPONSE.') then
|
||||
utilities.send_message(self, msg.chat.id, self.config.errors.chatter_response)
|
||||
return
|
||||
end
|
||||
local output = jdat.response
|
||||
|
||||
if output:match('^I HAVE NO RESPONSE.') then
|
||||
output = self.config.errors.chatter_response
|
||||
end
|
||||
|
||||
-- Let's clean up the response a little. Capitalization & punctuation.
|
||||
local filter = {
|
||||
['%aimi?%aimi?'] = self.info.first_name,
|
||||
['^%s*(.-)%s*$'] = '%1',
|
||||
['^%l'] = string.upper,
|
||||
['USER'] = msg.from.first_name
|
||||
}
|
||||
|
||||
for k,v in pairs(filter) do
|
||||
output = string.gsub(output, k, v)
|
||||
end
|
||||
|
||||
if not string.match(output, '%p$') then
|
||||
output = output .. '.'
|
||||
end
|
||||
-- Clean up the response here.
|
||||
output = utilities.trim(output)
|
||||
-- Simsimi will often refer to itself. Replace "simsimi" with the bot name.
|
||||
output = output:gsub('%aimi?%aimi?', self.info.first_name)
|
||||
-- Self-explanatory.
|
||||
output = output:gsub('USER', msg.from.first_name)
|
||||
-- Capitalize the first letter.
|
||||
output = output:gsub('^%l', string.upper)
|
||||
-- Add a period if there is no punctuation.
|
||||
output = output:gsub('%P$', '%1.')
|
||||
|
||||
utilities.send_message(self, msg.chat.id, output)
|
||||
|
||||
|
@ -12,7 +12,8 @@ function patterns:action(msg)
|
||||
local output = msg.reply_to_message.text or ''
|
||||
local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
|
||||
if not m2 then return true end
|
||||
local res, output = pcall(
|
||||
local res
|
||||
res, output = pcall(
|
||||
function()
|
||||
return output:gsub(m1, m2)
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ function xkcd:action(msg)
|
||||
end
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
local output = '*' .. jdat.safe_title .. '* ([' .. jdat.num .. '](' .. jdat.img .. '))\n' .. jdat.alt
|
||||
local output = '*' .. jdat.safe_title .. ' (*[' .. jdat.num .. '](' .. jdat.img .. ')*)*\n_' .. jdat.alt:gsub('_', '\\_') .. '_'
|
||||
|
||||
utilities.send_message(self, msg.chat.id, output, false, nil, true)
|
||||
|
||||
|
Reference in New Issue
Block a user