From 04dd411e52ee845418fb9b6ae3c91230f1a41470 Mon Sep 17 00:00:00 2001 From: Robert Hartnett Date: Wed, 17 Jan 2018 15:47:30 -0500 Subject: [PATCH] About command, and more killmail stats --- config.py.empty | 4 ++++ kb.py | 2 +- main.py | 38 ++++++++++++++++++++++++++++++++++++-- syscron.py | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/config.py.empty b/config.py.empty index 797f073..03d2be7 100644 --- a/config.py.empty +++ b/config.py.empty @@ -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 = "" diff --git a/kb.py b/kb.py index 82cb16c..3c3d836 100644 --- a/kb.py +++ b/kb.py @@ -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() diff --git a/main.py b/main.py index 8992379..310d916 100644 --- a/main.py +++ b/main.py @@ -20,6 +20,8 @@ import urllib counter = 0 +kcounter = 0 +lcounter = 0 start_time = datetime.datetime.utcnow() logger = logging.getLogger('discord') @@ -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): @@ -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) @@ -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: @@ -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 @@ -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: diff --git a/syscron.py b/syscron.py index d94d6c2..c77754e 100644 --- a/syscron.py +++ b/syscron.py @@ -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')