Skip to content

Commit

Permalink
About command, and more killmail stats
Browse files Browse the repository at this point in the history
  • Loading branch information
colcrunch committed Jan 17, 2018
1 parent dfebdd8 commit 04dd411
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config.py.empty
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ BOT_TOKEN = ""
#The symbol to be used before a command is entered
PREFIX = "]"

#Header Information
APP = "killbot"
CONTACT = ""

#What do you want the bot's "Playing" message to be? Limit: 12 Chars including spaces
msg = ""

Expand Down
2 changes: 1 addition & 1 deletion kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from discord.ext.commands import Bot

async def fetch(session, url):
headers = {'user-agent': 'application: https://github.com/colcrunch/killbot contact: rhartnett35@gmail.com','content-type': 'application/json'}
headers = {'user-agent': 'application: {0} contact: {1}'.format(config.APP, config.CONTACT),'content-type': 'application/json'}
with async_timeout.timeout(15):
async with session.get(url, headers=headers) as response:
return await response.json()
Expand Down
38 changes: 36 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import urllib

counter = 0
kcounter = 0
lcounter = 0
start_time = datetime.datetime.utcnow()

logger = logging.getLogger('discord')
Expand Down Expand Up @@ -51,9 +53,31 @@ async def ping():
"""PONG!"""
return await killbot.say("Pong!")

#---------------------------------------------------------------------
# About Command
# Displays general information about the bot.
#---------------------------------------------------------------------
@killbot.command(aliases=['a'], pass_context=True)
async def about(ctx):
"""Displays general information about the bot."""
info = await killbot.application_info()
owner = "{0}#{1}".format(info.owner.name, info.owner.discriminator)
link = "https://github.com/colcrunch/killbot"
about = ("Killbot is a general use discord bot for use with EVE Online."
"The aim of Killbot is to make it easy to get public info from the game and"
"to easily monitor zkillboard for kills that are interesting to you.")

embed = discord.Embed(title="About {}".format(killbot.user.name), description=about)
embed.set_author(name=killbot.user.name, icon_url=await esinfo.unWebp(killbot.user.avatar_url))
embed.set_thumbnail(url=await esinfo.unWebp(killbot.user.avatar_url))
embed.add_field(name="Bot Owner", value=owner, inline=False)
embed.add_field(name="GitHub", value=link, inline=False)

return await killbot.send_message(ctx.message.channel, embed=embed)

#---------------------------------------------------------------------
# Bot Stats Command
# Displays various statistics about the currnet bot.
# Displays various statistics about the current bot.
#---------------------------------------------------------------------
@killbot.command(aliases=['bs'], pass_context=True)
async def botStats(ctx):
Expand All @@ -71,7 +95,8 @@ async def botStats(ctx):
embed.set_thumbnail(url=await esinfo.unWebp(killbot.user.avatar_url))
embed.add_field(name="Servers", value=len(servers),inline=True)
embed.add_field(name="Uptime", value=await strftdelta(uptime), inline=True)
embed.add_field(name="Killmails Processed", value=counter, inline=False)
embed.add_field(name="Killmails Processed", value=counter, inline=True)
embed.add_field(name="Posted", value="**Kills:** {0} \n**Losses:** {1} \n**Total:** {2}".format(kcounter, lcounter, (kcounter+lcounter)), inline=True)

return await killbot.send_message(ctx.message.channel, embed=embed)

Expand Down Expand Up @@ -356,6 +381,8 @@ async def watch_redisq(chid, watchids):
logger.info(" Killboard watching started")
wids = config.watchids
global counter
global kcounter
global lcounter
await killbot.wait_until_ready()
channel = discord.Object(id=chid)
try:
Expand All @@ -382,18 +409,21 @@ async def watch_redisq(chid, watchids):
logger.info("Watching Attacker in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
kcounter += 1
break
elif 'corporation_id' in attacker and str(attacker['corporation_id']) in wids['corps']:
print("Watching Attacker in "+killID)
logger.info("Watching Attacker in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
kcounter += 1
break
elif 'character' in attacker and str(attacker['character_id']) in wids['characters']:
print("Watching Attacker in "+killID)
logger.info("Watching Attacker in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
kcounter += 1
break
else:
vic += 1
Expand All @@ -404,21 +434,25 @@ async def watch_redisq(chid, watchids):
logger.info("Watching Victim in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
lcounter += 1
elif vic == attacks and 'corporation_id' in victim and str(victim['corporation_id']) in wids['corps']:
print("Watching Victim in "+killID)
logger.info("Watching Victim in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
lcounter += 1
elif vic == attacks and 'character_id' in victim and str(victim['character_id']) in wids['characters']:
print("Watching Victim in "+killID)
logger.info("Watching Victim in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
lcounter += 1
elif vic == attacks and str(victim['ship_type_id']) in wids['shipTypes']:
print("Watching Ship Loss in "+killID)
logger.info("Watching Victim in "+killID)
embed = await kb.buildMsg(kills)
await killbot.send_message(channel, content=message, embed=embed)
lcounter += 1
else:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion syscron.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def regexp(pattern, input):
conn.close()

urlk = "https://esi.tech.ccp.is/latest/universe/system_kills/?datasource=tranquility"
headers = {'user-agent': 'application: https://github.com/colcrunch/killbot contact: rhartnett35@gmail.com','content-type': 'application/json'}
headers = {'user-agent': 'application: {0} contact: {1}'.format(config.APP, config.CONTACT),'content-type': 'application/json'}
r = requests.get(urlk, headers=headers)
kills = r.json()
conn = sqlite3.connect('systems.sqlite')
Expand Down

0 comments on commit 04dd411

Please sign in to comment.