add embed footers and timestamps to all current embeds (#34)

This commit is contained in:
Abigail Gold 2019-10-09 01:25:33 -04:00 committed by GitHub
parent a0cb64789b
commit 021a1312cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 32 deletions

View File

@ -10,6 +10,8 @@ General Public License, version 2.
import discord
import discord.ext.commands as commands
from datetime import datetime
class BaseCog(commands.Cog):
def __init__(self, bot):
@ -19,7 +21,12 @@ class BaseCog(commands.Cog):
@commands.command(name="info", aliases=["about"])
async def _info(self, ctx):
"""Shows info about qrm."""
embed = discord.Embed(title="About qrm", description=self.gs.info.description, colour=self.gs.colours.neutral)
embed = discord.Embed(title="About qrm",
description=self.gs.info.description,
colour=self.gs.colours.neutral,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
embed = embed.add_field(name="Authors", value=", ".join(self.gs.info.authors))
embed = embed.add_field(name="Contributing", value=self.gs.info.contributing)
embed = embed.add_field(name="License", value=self.gs.info.license)
@ -27,7 +34,13 @@ class BaseCog(commands.Cog):
@commands.command(name="ping")
async def _ping(self, ctx):
await ctx.send(f'**Pong!** Current ping is {self.bot.latency*1000:.1f} ms')
embed = discord.Embed(title="**Pong!**",
description=f'Current ping is {self.bot.latency*1000:.1f} ms',
colour=self.gs.colours.neutral,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
def setup(bot):

View File

@ -11,6 +11,8 @@ import discord
import discord.ext.commands as commands
import math
from datetime import datetime
class GridCog(commands.Cog):
def __init__(self, bot):
@ -36,12 +38,20 @@ class GridCog(commands.Cog):
grid += chr(ord('a') + int((latf - (int(latf/1)*1)) / (2.5/60)))
grid += "**"
embed = discord.Embed(title=f'Maidenhead Grid Locator for {float(lat):.6f}, {float(lon):.6f}',
description=grid, colour=self.gs.colours.good)
description=grid,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
else:
raise ValueError('Out of range.')
except Exception as e:
msg = f'Error generating grid square for {lat}, {lon}.'
embed = discord.Embed(title=msg, description=str(e), colour=self.gs.colours.bad)
embed = discord.Embed(title=msg, description=str(e),
colour=self.gs.colours.bad,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="ungrid", aliases=['loc'])
@ -56,16 +66,24 @@ class GridCog(commands.Cog):
if len(grid) >= 6:
embed = discord.Embed(title=f'Latitude and Longitude for {grid}',
description=f'**{loc[0]:.5f}, {loc[1]:.5f}**', colour=self.gs.colours.good,
url=f'https://www.openstreetmap.org/#map=13/{loc[0]:.5f}/{loc[1]:.5f}')
description=f'**{loc[0]:.5f}, {loc[1]:.5f}**', colour=self.gs.colours.good,
url=f'https://www.openstreetmap.org/#map=13/{loc[0]:.5f}/{loc[1]:.5f}',
timestamp=datetime.utcnow())
else:
embed = discord.Embed(title=f'Latitude and Longitude for {grid}',
description=f'**{loc[0]:.1f}, {loc[1]:.1f}**', colour=self.gs.colours.good,
url=f'https://www.openstreetmap.org/#map=10/{loc[0]:.1f}/{loc[1]:.1f}')
description=f'**{loc[0]:.1f}, {loc[1]:.1f}**', colour=self.gs.colours.good,
url=f'https://www.openstreetmap.org/#map=10/{loc[0]:.1f}/{loc[1]:.1f}',
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
except Exception as e:
msg = f'Error generating latitude and longitude for grid {grid}.'
embed = discord.Embed(title=msg, description=str(e), colour=self.gs.colours.bad)
embed = discord.Embed(title=msg, description=str(e),
colour=self.gs.colours.bad,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
else:
R = 6371
try:
@ -92,10 +110,18 @@ class GridCog(commands.Cog):
des = f'**Distance:** {d:.1f} km ({d_mi:.1f} mi)\n**Bearing:** {bearing:.1f}°'
embed = discord.Embed(title=f'Great Circle Distance and Bearing from {grid} to {grid2}',
description=des, colour=self.gs.colours.good)
description=des,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
except Exception as e:
msg = f'Error generating great circle distance and bearing from {grid} and {grid2}.'
embed = discord.Embed(title=msg, description=str(e), colour=self.gs.colours.bad)
embed = discord.Embed(title=msg, description=str(e),
colour=self.gs.colours.bad,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
def getCoords(self, grid: str):

View File

@ -28,15 +28,20 @@ class HamCog(commands.Cog):
'''Look up a Q Code.'''
with ctx.typing():
q = q.upper()
try:
code = self.qcodes[q]
embed = discord.Embed(title=q, description=self.qcodes[q], colour=self.gs.colours.good)
except:
embed = discord.Embed(title=f'Q Code {q} not found', colour=self.gs.colours.bad)
if q in self.qcodes:
embed = discord.Embed(title=q, description=self.qcodes[q],
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
else:
embed = discord.Embed(title=f'Q Code {q} not found',
colour=self.gs.colours.bad,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="phonetics", aliases=['ph', 'phoneticize', 'phoneticise', 'phone'])
async def _phonetics_lookup(self, ctx, *, msg : str):
async def _phonetics_lookup(self, ctx, *, msg: str):
'''Get phonetics for a word or phrase.'''
with ctx.typing():
result = ''
@ -47,7 +52,12 @@ class HamCog(commands.Cog):
else:
result += char
result += ' '
embed = discord.Embed(title=f'Phonetics for {msg}', description=result.title(), colour=self.gs.colours.good)
embed = discord.Embed(title=f'Phonetics for {msg}',
description=result.title(),
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="utc", aliases=['z'])
@ -56,7 +66,12 @@ class HamCog(commands.Cog):
with ctx.typing():
d = datetime.utcnow()
result = '**' + d.strftime('%Y-%m-%d %H:%M') + 'Z**'
embed = discord.Embed(title='The current time is:', description=result, colour=self.gs.colours.good)
embed = discord.Embed(title='The current time is:',
description=result,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)

View File

@ -11,6 +11,8 @@ import discord
import discord.ext.commands as commands
import json
from datetime import datetime
class MorseCog(commands.Cog):
def __init__(self, bot):
@ -21,7 +23,7 @@ class MorseCog(commands.Cog):
self.morse2ascii = {v: k for k, v in self.ascii2morse.items()}
@commands.command(name="morse", aliases=['cw'])
async def _morse(self, ctx, *, msg : str):
async def _morse(self, ctx, *, msg: str):
"""Converts ASCII to international morse code."""
with ctx.typing():
result = ''
@ -31,12 +33,16 @@ class MorseCog(commands.Cog):
except:
result += '<?>'
result += ' '
embed = discord.Embed(title=f'Morse Code for {msg}', description=result,
colour=self.gs.colours.good)
embed = discord.Embed(title=f'Morse Code for {msg}',
description=result,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="unmorse", aliases=['demorse', 'uncw', 'decw'])
async def _unmorse(self, ctx, *, msg : str):
async def _unmorse(self, ctx, *, msg: str):
'''Converts international morse code to ASCII.'''
with ctx.typing():
result = ''
@ -50,12 +56,16 @@ class MorseCog(commands.Cog):
except:
result += '<?>'
result += ' '
embed = discord.Embed(title=f'ASCII for {msg0}', description=result,
colour=self.gs.colours.good)
embed = discord.Embed(title=f'ASCII for {msg0}',
description=result,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="weight", aliases=["cwweight", 'cww'])
async def _weight(self, ctx, msg : str):
async def _weight(self, ctx, msg: str):
'''Calculates the CW Weight of a callsign.'''
with ctx.typing():
msg = msg.upper()
@ -69,8 +79,12 @@ class MorseCog(commands.Cog):
await ctx.send(res)
return
res = f'The CW weight is **{weight}**'
embed = discord.Embed(title=f'CW Weight of {msg}', description=res,
colour=self.gs.colours.good)
embed = discord.Embed(title=f'CW Weight of {msg}',
description=res,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)

View File

@ -13,6 +13,8 @@ import discord.ext.commands as commands
import random
import json
import aiohttp
from datetime import datetime
class StudyCog(commands.Cog):
def __init__(self, bot):
@ -62,7 +64,11 @@ class StudyCog(commands.Cog):
pool_questions = random.choice(pool_section)['questions']
question = random.choice(pool_questions)
embed = discord.Embed(title=question['id'], colour=self.gs.colours.good)
embed = discord.Embed(title=question['id'],
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
embed = embed.add_field(name='Question:', value=question['text'], inline=False)
embed = embed.add_field(name='Answers:', value=
'**A:** ' + question['answers']['A'] +
@ -86,13 +92,25 @@ class StudyCog(commands.Cog):
ans = ans.upper()
if ans == correct_ans:
result = f'Correct! The answer to {q_num} was **{correct_ans}**.'
embed = discord.Embed(title=f'{q_num} Answer', description=result, colour=self.gs.colours.good)
embed = discord.Embed(title=f'{q_num} Answer',
description=result,
colour=self.gs.colours.good,
timestamp=datetime.utcnow())
else:
result = f'Incorrect. The answer to {q_num} was **{correct_ans}**, not **{ans}**.'
embed = discord.Embed(title=f'{q_num} Answer', description=result, colour=self.gs.colours.bad)
embed = discord.Embed(title=f'{q_num} Answer',
description=result,
colour=self.gs.colours.bad,
timestamp=datetime.utcnow())
else:
result = f'The correct answer to {q_num} was **{correct_ans}**.'
embed = discord.Embed(title=f'{q_num} Answer', description=result, colour=self.gs.colours.neutral)
embed = discord.Embed(title=f'{q_num} Answer',
description=result,
colour=self.gs.colours.neutral,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)