about.lua: Less redundant if-else.
administration.lua: Will now attempt to unban kicked users in supergrounds. remind.lua: New plugin! Set a reminder. control.lua: No more lost control messages.
This commit is contained in:
parent
4f9420ae31
commit
effe34cb32
@ -13,13 +13,9 @@ local action = function(msg)
|
||||
|
||||
local message = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.'
|
||||
|
||||
if msg.new_chat_participant and msg.new_chat_participant.id == bot.id then
|
||||
sendMessage(msg.chat.id, message, true)
|
||||
return
|
||||
elseif msg.text_lower:match('^/about[@'..bot.username..']*') then
|
||||
sendMessage(msg.chat.id, message, true)
|
||||
return
|
||||
elseif msg.text_lower:match('^/start') then
|
||||
if (msg.new_chat_participant and msg.new_chat_participant.id == bot.id)
|
||||
or msg.text_lower:match('^/about[@'..bot.username..']*')
|
||||
or msg.text_lower:match('^/start') then
|
||||
sendMessage(msg.chat.id, message, true)
|
||||
return
|
||||
end
|
||||
|
@ -254,6 +254,9 @@ local commands = {
|
||||
return true
|
||||
end
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
if msg.chat.type == 'supergroup' then
|
||||
unbanChatMember(msg.chat.id, msg.from.id)
|
||||
end
|
||||
local output = flags[2].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.from.id, output)
|
||||
end
|
||||
@ -282,6 +285,9 @@ local commands = {
|
||||
if group.flags[3] == true then
|
||||
if msg.from.name:match('[\216-\219][\128-\191]') or msg.from.name:match('') or msg.from.name:match('') then
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
if msg.chat.type == 'supergroup' then
|
||||
unbanChatMember(msg.chat.id, msg.from.id)
|
||||
end
|
||||
local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.from.id, output)
|
||||
return
|
||||
@ -320,6 +326,9 @@ local commands = {
|
||||
end
|
||||
if admin_temp.flood[msg.chat.id_str][msg.from.id_str] > 99 then
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
if msg.chat.type == 'supergroup' then
|
||||
unbanChatMember(msg.chat.id, msg.from.id)
|
||||
end
|
||||
local output = flags[5].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.from.id, output)
|
||||
admin_temp.flood[msg.chat.id_str][msg.from.id_str] = nil
|
||||
@ -344,6 +353,9 @@ local commands = {
|
||||
if group.flags[3] == true then
|
||||
if msg.new_chat_participant.name:match('[\216-\219][\128-\191]') or msg.new_chat_participant.name:match('') or msg.new_chat_participant.name:match('') then
|
||||
drua.kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
if msg.chat.type == 'supergroup' then
|
||||
unbanChatMember(msg.chat.id, msg.from.id)
|
||||
end
|
||||
local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.new_chat_participant.id, output)
|
||||
return
|
||||
@ -617,6 +629,9 @@ local commands = {
|
||||
return
|
||||
end
|
||||
drua.kick_user(msg.chat.id, target.id)
|
||||
if msg.chat.type == 'supergroup' then
|
||||
unbanChatMember(msg.chat.id, target.id)
|
||||
end
|
||||
sendMessage(msg.chat.id, target.name .. ' has been kicked.')
|
||||
end
|
||||
},
|
||||
|
@ -9,7 +9,7 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
if msg.date < os.time() then return end
|
||||
if msg.date < os.time() - 1 then return end
|
||||
|
||||
if msg.text:match('^/reload') then
|
||||
bot_init()
|
||||
|
102
plugins/remind.lua
Normal file
102
plugins/remind.lua
Normal file
@ -0,0 +1,102 @@
|
||||
database.reminders = database.reminders or {}
|
||||
|
||||
local command = 'remind <duration> <message>'
|
||||
local doc = [[```
|
||||
/remind <duration> <message>
|
||||
Repeats a message after a duration of time, in minutes.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/remind'
|
||||
}
|
||||
|
||||
local action = function(msg)
|
||||
-- Ensure there are arguments. If not, send doc.
|
||||
local input = msg.text:input()
|
||||
if not input then
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Ensure first arg is a number. If not, send doc.
|
||||
local duration = get_word(input, 1)
|
||||
if not tonumber(duration) then
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Duration must be between one minute and one year (approximately).
|
||||
duration = tonumber(duration)
|
||||
if duration < 1 then
|
||||
duration = 1
|
||||
elseif duration > 526000 then
|
||||
duration = 526000
|
||||
end
|
||||
-- Ensure there is a second arg.
|
||||
local message = input:input()
|
||||
if not message then
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
-- Make a database entry for the group/user if one does not exist.
|
||||
database.reminders[msg.chat.id_str] = database.reminders[msg.chat.id_str] or {}
|
||||
-- Limit group reminders to 10 and private reminders to 50.
|
||||
if msg.chat.type ~= 'private' and table_size(database.reminders[msg.chat.id_str]) > 9 then
|
||||
sendReply(msg, 'Sorry, this group already has ten reminders.')
|
||||
return
|
||||
elseif msg.chat.type == 'private' and table_size(database.reminders[msg.chat.id_str]) > 49 then
|
||||
sendReply(msg, 'Sorry, you already have fifty reminders.')
|
||||
return
|
||||
end
|
||||
-- Put together the reminder with the expiration, message, and message to reply to.
|
||||
local reminder = {
|
||||
time = os.time() + duration * 60,
|
||||
message = message
|
||||
}
|
||||
table.insert(database.reminders[msg.chat.id_str], reminder)
|
||||
local output = 'I will remind you in ' .. duration
|
||||
if duration == 1 then
|
||||
output = output .. ' minute!'
|
||||
else
|
||||
output = output .. ' minutes!'
|
||||
end
|
||||
sendReply(msg, output)
|
||||
end
|
||||
|
||||
local cron = function()
|
||||
local time = os.time()
|
||||
-- Iterate over the group entries in the reminders database.
|
||||
for chat_id, group in pairs(database.reminders) do
|
||||
local new_group = {}
|
||||
-- Iterate over each reminder.
|
||||
for i, reminder in ipairs(group) do
|
||||
-- If the reminder is past-due, send it and nullify it.
|
||||
-- Otherwise, add it to the replacement table.
|
||||
if time > reminder.time then
|
||||
local output = 'Reminder:\n"' .. reminder.message .. '"'
|
||||
local res = sendMessage(chat_id, output, true)
|
||||
-- If the message fails to send, save it for later.
|
||||
if res then
|
||||
reminder = nil
|
||||
else
|
||||
table.insert(new_group, reminder)
|
||||
end
|
||||
else
|
||||
table.insert(new_group, reminder)
|
||||
end
|
||||
end
|
||||
-- Nullify the original table and replace it with the new one.
|
||||
group = nil
|
||||
database.reminders[chat_id] = new_group
|
||||
-- Nullify the table if it is empty.
|
||||
if #new_group == 0 then
|
||||
database.reminders[chat_id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
cron = cron,
|
||||
command = command,
|
||||
doc = doc
|
||||
}
|
Reference in New Issue
Block a user