Advertisement
Guest User

Untitled

a guest
May 26th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #
  2. # This file is part of Magnet2.
  3. # Copyright (c) 2011 Grom PE
  4. #
  5. # Magnet2 is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Magnet2 is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Magnet2. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. import time, xmpp
  19. from magnet_api import *
  20. from magnet_utils import *
  21.  
  22. adevoice_db = {}
  23.  
  24. def check_adevoice(bot, room, nick, jid=None):
  25. if bot.in_roster(room, nick) and bot.roster[room][nick][ROSTER_ROLE] == 'moderator': return
  26. prefix = bot.get_config(room, 'db_prefix')
  27. if not prefix in adevoice_db: return
  28. if nick in adevoice_db[prefix]:
  29. reason = adevoice_db[prefix][nick]['reason']
  30. reason = reason and 'Nick banned (%s)'%(reason) or 'Nick banned.'
  31. bot.client.send(iq_set_role(room, nick, 'none', reason))
  32. else:
  33. if not jid and not bot.in_roster(room, nick): return
  34. if not jid: jid = bot.roster[room][nick][ROSTER_JID]
  35. if not jid: return
  36. jid = xmpp.JID(jid).getStripped().lower()
  37. if jid in adevoice_db[prefix]:
  38. reason = adevoice_db[prefix][jid]['reason']
  39. reason = reason and 'Banned (%s)'%(reason) or 'Banned.'
  40. bot.client.send(iq_set_role(room, nick, 'visitor', reason))
  41.  
  42. def command_adevoice(bot, room, nick, access_level, parameters, message):
  43. if parameters == '': return "Expected <target nick or JID> [reason]"
  44. (target, reason) = separate_target_reason(bot, room, parameters)
  45.  
  46. if target in bot.roster[room] and bot.roster[room][target][ROSTER_ROLE] == 'moderator':
  47. return 'Can not autodevoice a moderator.'
  48.  
  49. prefix = bot.get_config(room, 'db_prefix')
  50. if not prefix in adevoice_db: adevoice_db[prefix] = {}
  51.  
  52. if target in adevoice_db[prefix]:
  53. return '%s is already in autodevoice.'%(target)
  54.  
  55. adevoice_db[prefix][target] = {
  56. 'time': time.time(),
  57. 'reason': reason
  58. }
  59. check_adevoice(bot, room, target)
  60. return '%s is autodevoiceed.'%(target)
  61.  
  62. def command_deladevoice(bot, room, nick, access_level, parameters, message):
  63. if not parameters: return "Expected <target nick or JID>"
  64. target = parameters
  65. if target[-1] == ' ': target = target[0:-1]
  66.  
  67. prefix = bot.get_config(room, 'db_prefix')
  68. if not prefix in adevoice_db or not target in adevoice_db[prefix]:
  69. return '%s is not autodevoiceed.'%(target)
  70.  
  71. del adevoice_db[prefix][target]
  72. return 'Autodevoice lifted from %s.'%(target)
  73.  
  74. def command_adevoiceed(bot, room, nick, access_level, parameters, message):
  75. prefix = bot.get_config(room, 'db_prefix')
  76.  
  77. if not parameters:
  78. # list all
  79. if message.getType() == 'groupchat':
  80. # for privacy reasons
  81. return "Specify the target, or use without parameters in private."
  82. if not prefix in adevoice_db or len(adevoice_db[prefix]) == 0:
  83. return "Autodevoice list is empty."
  84. return "Autodevoiceed: %s."%(', '.join(adevoice_db[prefix].keys()))
  85.  
  86. target = parameters
  87. if target[-1] == ' ': target = target[0:-1]
  88.  
  89. if not prefix in adevoice_db or not target in adevoice_db[prefix]:
  90. return '%s is not autodevoiceed.'%(target)
  91.  
  92. seconds = time.time()-adevoice_db[prefix][target]['time']
  93. ago = timeformat(seconds)
  94. reason = adevoice_db[prefix][target]['reason']
  95. return '%s is set to autodevoice %s ago with reason: %s.'%(target, ago, reason)
  96.  
  97. def event_nick_changed(bot, (presence, room, nick, newnick)):
  98. check_adevoice(bot, room, newnick)
  99.  
  100. def event_joined(bot, (presence, room, nick, jid, role, affiliation, status, status_text)):
  101. if role != 'moderator':
  102. check_adevoice(bot, room, nick, jid)
  103.  
  104. def event_room_roster(bot, (presence, room, nick, jid, role, affiliation, status, status_text)):
  105. if role != 'moderator':
  106. check_adevoice(bot, room, nick, jid)
  107.  
  108. def load(bot):
  109. global adevoice_db
  110. adevoice_db = bot.load_database('adevoice') or {}
  111. bot.add_command('adevoice', command_adevoice, LEVEL_ADMIN)
  112. bot.add_command('deladevoice', command_deladevoice, LEVEL_ADMIN)
  113. bot.add_command('adevoiceed', command_adevoiceed, LEVEL_ADMIN)
  114.  
  115. def save(bot):
  116. bot.save_database('adevoice', adevoice_db)
  117.  
  118. def unload(bot):
  119. pass
  120.  
  121. def info(bot):
  122. return 'Autodevoice plugin v1.0.1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement