Advertisement
Buzzrz

Test_promote.lua

Jan 23rd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. do
  2.  
  3. local function admin_user_promote(receiver, member_username, member_id)
  4. local data = load_data(_config.moderation.data)
  5. if not data['admins'] then
  6. data['admins'] = {}
  7. save_data(_config.moderation.data, data)
  8. end
  9. if data['admins'][tostring(member_id)] then
  10. send_large_msg(receiver, member_username..' is already as admin.')
  11. end
  12. data['admins'][tostring(member_id)] = member_username
  13. save_data(_config.moderation.data, data)
  14. send_large_msg(receiver, '@'..member_username..' has been promoted as admin.')
  15. end
  16.  
  17. local function admin_user_promote_by_reply(extra, success, result)
  18. local msg = result
  19. local full_name = (msg.from.first_name or '')..' '..(msg.from.last_name or '')
  20. if msg.from.username then
  21. member_username = '@'.. msg.from.username
  22. else
  23. member_username = full_name
  24. end
  25. local member_id = msg.from.id
  26. if msg.to.type == 'chat' then
  27. return admin_user_promote(receiver, member_username, member_id)
  28. end
  29. end
  30.  
  31. local function admin_user_demote(receiver, member_username, member_id)
  32. local data = load_data(_config.moderation.data)
  33. if not data['admins'] then
  34. data['admins'] = {}
  35. save_data(_config.moderation.data, data)
  36. end
  37. if not data['admins'][tostring(member_id)] then
  38. send_large_msg(receiver, member_username..' is not an admin.')
  39. end
  40. data['admins'][tostring(member_id)] = nil
  41. save_data(_config.moderation.data, data)
  42. send_large_msg(receiver, 'Admin '..member_username..' has been demoted.')
  43. end
  44.  
  45. local function admin_user_demote_by_reply(extra, success, result)
  46. local msg = result
  47. local full_name = (msg.from.first_name or '')..' '..(msg.from.last_name or '')
  48. if msg.from.username then
  49. member_username = '@'.. msg.from.username
  50. else
  51. member_username = full_name
  52. end
  53. local member_id = msg.from.id
  54. if msg.to.type == 'chat' then
  55. return admin_user_demote(receiver, member_username, member_id)
  56. end
  57. end
  58.  
  59. local function run(msg, matches)
  60. local receiver = get_receiver(msg)
  61. if matches[1] == 'spromote' and is_sudo(msg) then
  62. if type(msg.reply_id) ~= 'nil' then
  63. msgr = get_message(msg.reply_id, admin_user_promote_by_reply, false)
  64. end
  65. elseif matches[1] == 'sdemote' and is_sudo(msg) then
  66. if type(msg.reply_id) ~= 'nil' then
  67. msgr = get_message(msg.reply_id, admin_user_demote_by_reply, false)
  68. end
  69. end
  70. end
  71.  
  72. return {
  73. patterns = {
  74. "^[!/#](spromote)$",
  75. "^[!/#](sdemote)$"
  76. },
  77. run = run
  78. }
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement