Page MenuHomePhabricator (Chris)

tempmute.lua
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

tempmute.lua

--[[
mattata v2.0 - Tempmute Plugin
]]
local plugin = {}
plugin.name = 'tempmute'
plugin.category = 'admin'
plugin.description = 'Temporarily mute users'
plugin.commands = { 'tempmute', 'tmute' }
plugin.help = '/tempmute [user] <duration> - Temporarily mutes a user. Duration format: 1h, 2d.'
plugin.group_only = true
plugin.admin_only = true
local function parse_duration(str)
if not str then return nil end
local total = 0
for num, unit in str:gmatch('(%d+)(%a)') do
num = tonumber(num)
if unit == 's' then total = total + num
elseif unit == 'm' then total = total + num * 60
elseif unit == 'h' then total = total + num * 3600
elseif unit == 'd' then total = total + num * 86400
elseif unit == 'w' then total = total + num * 604800
end
end
return total > 0 and total or nil
end
function plugin.on_message(api, message, ctx)
local tools = require('telegram-bot-lua.tools')
local permissions = require('src.core.permissions')
if not permissions.can_restrict(api, message.chat.id) then
return api.send_message(message.chat.id, 'I need the "Restrict Members" admin permission to use this command.')
end
local user_id, duration_str
if message.reply and message.reply.from then
user_id = message.reply.from.id
duration_str = message.args
elseif message.args then
user_id, duration_str = message.args:match('^(%S+)%s+(.+)$')
if not user_id then user_id = message.args end
end
if not user_id then
return api.send_message(message.chat.id, 'Please specify the user and duration.')
end
if tonumber(user_id) == nil then
local name = user_id:match('^@?(.+)$')
user_id = ctx.redis.get('username:' .. name:lower())
end
user_id = tonumber(user_id)
if not user_id or user_id == api.info.id then return end
local duration = parse_duration(duration_str)
if not duration or duration < 60 then
return api.send_message(message.chat.id, 'Please provide a valid duration (min 1 minute).')
end
if permissions.is_group_admin(api, message.chat.id, user_id) then
return api.send_message(message.chat.id, 'I can\'t mute an admin.')
end
local perms = {
can_send_messages = false,
can_send_audios = false,
can_send_documents = false,
can_send_photos = false,
can_send_videos = false,
can_send_video_notes = false,
can_send_voice_notes = false,
can_send_polls = false,
can_send_other_messages = false,
can_add_web_page_previews = false,
can_invite_users = false,
can_change_info = false,
can_pin_messages = false,
can_manage_topics = false
}
local success = api.restrict_chat_member(message.chat.id, user_id, perms, { until_date = os.time() + duration })
if not success then
return api.send_message(message.chat.id, 'I don\'t have permission to mute users.')
end
local admin_name = tools.escape_html(message.from.first_name)
local target_info = api.get_chat(user_id)
local target_name = target_info and target_info.result and tools.escape_html(target_info.result.first_name) or tostring(user_id)
return api.send_message(message.chat.id, string.format(
'<a href="tg://user?id=%d">%s</a> has temporarily muted <a href="tg://user?id=%d">%s</a> for %s.',
message.from.id, admin_name, user_id, target_name, duration_str or 'unknown'
), { parse_mode = 'html' })
end
return plugin

File Metadata

Mime Type
text/html
Expires
Sun, Nov 15, 1:29 AM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
131704
Default Alt Text
tempmute.lua (3 KB)

Event Timeline