mirror of
https://github.com/nikdoof/dropbot.git
synced 2025-12-19 20:59:24 +00:00
Format the kill/loss mails better.
This commit is contained in:
@@ -10,7 +10,7 @@ import urlparse
|
||||
from sleekxmpp import ClientXMPP
|
||||
from redis import Redis, ConnectionPool
|
||||
import requests
|
||||
from humanize import intcomma
|
||||
from humanize import intcomma, naturaltime
|
||||
from pyzkb import ZKillboard
|
||||
from eveapi import EVEAPIConnection
|
||||
|
||||
@@ -604,10 +604,15 @@ class DropBot(ClientXMPP):
|
||||
else:
|
||||
url = ' - https://zkillboard.com/kill/{}/'.format(kill_id)
|
||||
|
||||
return '{} ({}) in {}, {} attacker(s), {} ISK lost{}'.format(
|
||||
age = (datetime.utcnow() - datetime.strptime(kill['killTime'], '%Y-%m-%d %H:%M:%S'))
|
||||
if age.total_seconds() > 60 * 60:
|
||||
return
|
||||
|
||||
return '{} ({}) in {}, {}, {} attacker(s), {} ISK lost{}'.format(
|
||||
kill['victim']['characterName'],
|
||||
self.types[unicode(kill['victim']['shipTypeID'])],
|
||||
self.map.node[int(kill['solarSystemID'])]['name'],
|
||||
naturaltime(age),
|
||||
len(kill['attackers']),
|
||||
intcomma(kill['zkb']['totalValue']),
|
||||
url,
|
||||
|
||||
@@ -15,19 +15,27 @@ class ZKillboardStompListener(object):
|
||||
|
||||
def on_message(self, headers, message):
|
||||
kill = json.loads(message)
|
||||
kill_type = None
|
||||
|
||||
# Tag kills
|
||||
for attacker in kill['attackers']:
|
||||
if int(attacker['corporationID']) in self.bot.kill_corps:
|
||||
kill_type = 'KILL'
|
||||
break
|
||||
else:
|
||||
if int(kill['victim']['corporationID']) not in self.bot.kill_corps:
|
||||
return
|
||||
|
||||
print message
|
||||
# Tag losses
|
||||
if int(kill['victim']['corporationID']) in self.bot.kill_corps:
|
||||
kill_type = 'LOSS'
|
||||
|
||||
if not kill_type:
|
||||
return
|
||||
|
||||
body, html = self.bot.call_command('kill', [], None, no_url=False, raw=kill)
|
||||
text = 'New Kill: {}'.format(body)
|
||||
if not self.bot.kills_muted:
|
||||
for room in self.bot.rooms:
|
||||
self.bot.send_message(room, text, mtype='groupchat')
|
||||
if body:
|
||||
text = '[{}] {}'.format(kill_type, body)
|
||||
if not self.bot.kills_muted:
|
||||
for room in self.bot.rooms:
|
||||
self.bot.send_message(room, text, mtype='groupchat')
|
||||
|
||||
|
||||
def connect(self, url):
|
||||
|
||||
Reference in New Issue
Block a user