Add config to disable all kill messages.

This commit is contained in:
2014-09-03 22:14:07 +01:00
parent ee4ad2b57e
commit 26481f0471
2 changed files with 22 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ class DropBot(ClientXMPP):
self.hidden_commands = ['cmd_prefix']
self.last_killdate = datetime.utcnow()
self.kill_corps = [int(x) for x in kwargs.pop('kill_corps', [])]
self.kill_check_timeout = kwargs.pop('kill_check_timeout', 300)
self.kills_disabled = kwargs.pop('kills_disabled', '0') == '1'
self.kills_muted = False
self.office_api_key_keyid = kwargs.pop('office_api_keyid', None)
self.office_api_key_vcode = kwargs.pop('office_api_vcode', None)
@@ -54,7 +54,11 @@ class DropBot(ClientXMPP):
self.redis = Redis(connection_pool=self.redis_pool)
self.map = Map.from_json(pkgutil.get_data('dropbot', 'data/map.json'))
super(DropBot, self).__init__(*args, **kwargs)
jid = kwargs.pop('jid')
password = kwargs.pop('password')
super(DropBot, self).__init__(jid, password)
self.register_plugin('xep_0030') # Service Discovery
self.register_plugin('xep_0045') # Multi-User Chat
self.register_plugin('xep_0199') # XMPP Ping
@@ -95,9 +99,13 @@ class DropBot(ClientXMPP):
for room in self.rooms:
self.plugin['xep_0045'].joinMUC(room, self.nickname, wait=True)
# Start the killchecker
self.stomp = ZKillboardStompListener(self)
self.stomp.connect('tcp://eve-kill.net:61613')
# Start the killchecker if we have corps to monitor
if len(self.kill_corps) > 0 and not self.kills_disabled:
logging.info('Starting ZKB Stomp monitor for corps: {}'.format(', '.join(self.kill_corps)))
self.stomp = ZKillboardStompListener(self)
self.stomp.connect('tcp://eve-kill.net:61613')
else:
logging.info('Kill monitoring disabled.')
def call_command(self, command, *args, **kwargs):
if hasattr(self, 'cmd_%s' % command):

View File

@@ -1,6 +1,7 @@
import stomp
import urlparse
import json
import logging
urlparse.uses_netloc.append('tcp')
@@ -9,6 +10,7 @@ class ZKillboardStompListener(stomp.listener.ConnectionListener):
def __init__(self, bot):
self.bot = bot
self.conn = None
self.ids = [None for x in range(50)]
def on_error(self, headers, message):
pass
@@ -17,6 +19,13 @@ class ZKillboardStompListener(stomp.listener.ConnectionListener):
kill = json.loads(message)
kill_type = None
if kill['killID'] in self.ids:
logging.error('Duplicate message')
return
self.ids.pop(0)
self.ids.append(kill['killID'])
# Tag kills
for attacker in kill['attackers']:
if int(attacker['corporationID']) in self.bot.kill_corps: