Created
July 21, 2011 19:23
-
-
Save thomasleveil/1097979 to your computer and use it in GitHub Desktop.
B3 BanPlugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'NinjaNife' | |
__version__ = '1.0' | |
import string, re | |
import b3.events | |
import b3.plugin | |
#-------------------------------------------------------------------------------------------------- | |
class BanPlugin(b3.plugin.Plugin): | |
def onStartup(self): | |
# get the admin plugin so we can register commands | |
self._adminPlugin = self.console.getPlugin('admin') | |
if not self._adminPlugin: | |
# something is wrong, can't start without admin plugin | |
self.error('Could not find admin plugin') | |
return | |
# Register commands | |
for cmd in self.config.options('commands'): | |
level = self.config.get('commands', cmd) | |
sp = cmd.split('-') | |
alias = None | |
if len(sp) == 2: | |
cmd, alias = sp | |
func = self._adminPlugin.getCmd(cmd) | |
if func: | |
self._adminPlugin.registerCommand(self, cmd, level, func, alias) | |
def cmd_ban1(self, data, client=None, cmd=None): | |
"""\ | |
<name> [<reason>] - ban a player | |
""" | |
m = self._adminPlugin.parseUserCmd(data) | |
if not m: | |
client.message('^7Invalid parameters') | |
return False | |
cid, keyword = m | |
reason = self._adminPlugin.getReason(keyword) | |
if not reason and client.maxLevel < self.config.getint('settings', 'noreason_level'): | |
client.message('^1ERROR: ^7You must supply a reason') | |
return False | |
sclient = self._adminPlugin.findClientPrompt(cid, client) | |
if sclient: | |
if sclient.cid == client.cid: | |
self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName)) | |
return True | |
elif sclient.maxLevel >= client.maxLevel: | |
if sclient.maskGroup: | |
client.message('^7%s ^7is a masked higher level player, can\'t ban' % client.exactName) | |
else: | |
self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName)) | |
return True | |
else: | |
sclient.groupBits = 0 | |
sclient.save() | |
duration = self.config.getDuration('settings', 'ban1') | |
sclient.tempban(reason, keyword, duration, client) | |
return True | |
elif re.match('^[0-9]+$', cid): | |
# failsafe, do a manual client id ban | |
duration = self.config.getDuration('settings', 'ban1') | |
self.console.tempban(cid, reason, duration, client) | |
def cmd_ban2(self, data, client=None, cmd=None): | |
"""\ | |
<name> [<reason>] - ban a player | |
""" | |
m = self._adminPlugin.parseUserCmd(data) | |
if not m: | |
client.message('^7Invalid parameters') | |
return False | |
cid, keyword = m | |
reason = self._adminPlugin.getReason(keyword) | |
if not reason and client.maxLevel < self.config.getint('settings', 'noreason_level'): | |
client.message('^1ERROR: ^7You must supply a reason') | |
return False | |
sclient = self._adminPlugin.findClientPrompt(cid, client) | |
if sclient: | |
if sclient.cid == client.cid: | |
self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName)) | |
return True | |
elif sclient.maxLevel >= client.maxLevel: | |
if sclient.maskGroup: | |
client.message('^7%s ^7is a masked higher level player, can\'t ban' % client.exactName) | |
else: | |
self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName)) | |
return True | |
else: | |
sclient.groupBits = 0 | |
sclient.save() | |
duration = self.config.getDuration('settings', 'ban2') | |
sclient.tempban(reason, keyword, duration, client) | |
return True | |
elif re.match('^[0-9]+$', cid): | |
# failsafe, do a manual client id ban | |
duration = self.config.getDuration('settings', 'ban2') | |
self.console.tempban(cid, reason, duration, client) | |
def cmd_ban3(self, data, client=None, cmd=None): | |
"""\ | |
<name> [<reason>] - ban a player | |
""" | |
m = self._adminPlugin.parseUserCmd(data) | |
if not m: | |
client.message('^7Invalid parameters') | |
return False | |
cid, keyword = m | |
reason = self._adminPlugin.getReason(keyword) | |
if not reason and client.maxLevel < self.config.getint('settings', 'noreason_level'): | |
client.message('^1ERROR: ^7You must supply a reason') | |
return False | |
sclient = self._adminPlugin.findClientPrompt(cid, client) | |
if sclient: | |
if sclient.cid == client.cid: | |
self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName)) | |
return True | |
elif sclient.maxLevel >= client.maxLevel: | |
if sclient.maskGroup: | |
client.message('^7%s ^7is a masked higher level player, can\'t ban' % client.exactName) | |
else: | |
self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName)) | |
return True | |
else: | |
sclient.groupBits = 0 | |
sclient.save() | |
duration = self.config.getDuration('settings', 'ban3') | |
sclient.tempban(reason, keyword, duration, client) | |
return True | |
elif re.match('^[0-9]+$', cid): | |
# failsafe, do a manual client id ban | |
duration = self.config.getDuration('settings', 'ban3') | |
self.console.tempban(cid, reason, duration, client) | |
def cmd_ban4(self, data, client=None, cmd=None): | |
"""\ | |
<name> [<reason>] - ban a player | |
""" | |
m = self._adminPlugin.parseUserCmd(data) | |
if not m: | |
client.message('^7Invalid parameters') | |
return False | |
cid, keyword = m | |
reason = self._adminPlugin.getReason(keyword) | |
if not reason and client.maxLevel < self.config.getint('settings', 'noreason_level'): | |
client.message('^1ERROR: ^7You must supply a reason') | |
return False | |
sclient = self._adminPlugin.findClientPrompt(cid, client) | |
if sclient: | |
if sclient.cid == client.cid: | |
self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName)) | |
return True | |
elif sclient.maxLevel >= client.maxLevel: | |
if sclient.maskGroup: | |
client.message('^7%s ^7is a masked higher level player, can\'t ban' % client.exactName) | |
else: | |
self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName)) | |
return True | |
else: | |
sclient.groupBits = 0 | |
sclient.save() | |
duration = self.config.getDuration('settings', 'ban4') | |
sclient.tempban(reason, keyword, duration, client) | |
return True | |
elif re.match('^[0-9]+$', cid): | |
# failsafe, do a manual client id ban | |
duration = self.config.getDuration('settings', 'ban4') | |
self.console.tempban(cid, reason, duration, client) | |
def cmd_ban5(self, data, client=None, cmd=None): | |
"""\ | |
<name> [<reason>] - ban a player | |
""" | |
m = self._adminPlugin.parseUserCmd(data) | |
if not m: | |
client.message('^7Invalid parameters') | |
return False | |
cid, keyword = m | |
reason = self._adminPlugin.getReason(keyword) | |
if not reason and client.maxLevel < self.config.getint('settings', 'noreason_level'): | |
client.message('^1ERROR: ^7You must supply a reason') | |
return False | |
sclient = self._adminPlugin.findClientPrompt(cid, client) | |
if sclient: | |
if sclient.cid == client.cid: | |
self.console.say(self._adminPlugin.getMessage('ban_self', client.exactName)) | |
return True | |
elif sclient.maxLevel >= client.maxLevel: | |
if sclient.maskGroup: | |
client.message('^7%s ^7is a masked higher level player, can\'t ban' % client.exactName) | |
else: | |
self.console.say(self._adminPlugin.getMessage('ban_denied', client.exactName, sclient.exactName)) | |
return True | |
else: | |
sclient.groupBits = 0 | |
sclient.save() | |
duration = self.config.getDuration('settings', 'ban5') | |
sclient.tempban(reason, keyword, duration, client) | |
return True | |
elif re.match('^[0-9]+$', cid): | |
# failsafe, do a manual client id ban | |
duration = self.config.getDuration('settings', 'ban5') | |
self.console.tempban(cid, reason, duration, client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment