Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do
- local function admin_user_promote(receiver, member_username, member_id)
- local data = load_data(_config.moderation.data)
- if not data['admins'] then
- data['admins'] = {}
- save_data(_config.moderation.data, data)
- end
- if data['admins'][tostring(member_id)] then
- send_large_msg(receiver, member_username..' is already as admin.')
- end
- data['admins'][tostring(member_id)] = member_username
- save_data(_config.moderation.data, data)
- send_large_msg(receiver, '@'..member_username..' has been promoted as admin.')
- end
- local function admin_user_promote_by_reply(extra, success, result)
- local msg = result
- local full_name = (msg.from.first_name or '')..' '..(msg.from.last_name or '')
- if msg.from.username then
- member_username = '@'.. msg.from.username
- else
- member_username = full_name
- end
- local member_id = msg.from.id
- if msg.to.type == 'chat' then
- return admin_user_promote(receiver, member_username, member_id)
- end
- end
- local function admin_user_demote(receiver, member_username, member_id)
- local data = load_data(_config.moderation.data)
- if not data['admins'] then
- data['admins'] = {}
- save_data(_config.moderation.data, data)
- end
- if not data['admins'][tostring(member_id)] then
- send_large_msg(receiver, member_username..' is not an admin.')
- end
- data['admins'][tostring(member_id)] = nil
- save_data(_config.moderation.data, data)
- send_large_msg(receiver, 'Admin '..member_username..' has been demoted.')
- end
- local function admin_user_demote_by_reply(extra, success, result)
- local msg = result
- local full_name = (msg.from.first_name or '')..' '..(msg.from.last_name or '')
- if msg.from.username then
- member_username = '@'.. msg.from.username
- else
- member_username = full_name
- end
- local member_id = msg.from.id
- if msg.to.type == 'chat' then
- return admin_user_demote(receiver, member_username, member_id)
- end
- end
- local function run(msg, matches)
- local receiver = get_receiver(msg)
- if matches[1] == 'spromote' and is_sudo(msg) then
- if type(msg.reply_id) ~= 'nil' then
- msgr = get_message(msg.reply_id, admin_user_promote_by_reply, false)
- end
- elseif matches[1] == 'sdemote' and is_sudo(msg) then
- if type(msg.reply_id) ~= 'nil' then
- msgr = get_message(msg.reply_id, admin_user_demote_by_reply, false)
- end
- end
- end
- return {
- patterns = {
- "^[!/#](spromote)$",
- "^[!/#](sdemote)$"
- },
- run = run
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement