mirror of
https://github.com/miaowware/qrm2.git
synced 2024-11-26 17:58:40 -05:00
Merge pull request #175 from classabbyamp/5c-sendlogic
Fixed bad file/embed sending logic in multiple commands
This commit is contained in:
commit
94f9865103
@ -18,6 +18,9 @@ import common as cmn
|
||||
|
||||
|
||||
class ImageCog(commands.Cog):
|
||||
gl_url = ('http://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=NOAAtopo.evif'
|
||||
'&imgsize=320&dynimg=y&opt=-p&lat=&lon=&alt=&tle=&date=0&utc=&jd=')
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.bandcharts = cmn.ImagesGroup(cmn.paths.bandcharts / "meta.json")
|
||||
@ -27,9 +30,8 @@ class ImageCog(commands.Cog):
|
||||
@commands.command(name="bandplan", aliases=['plan', 'bands'], category=cmn.cat.ref)
|
||||
async def _bandplan(self, ctx: commands.Context, region: str = ''):
|
||||
'''Posts an image of Frequency Allocations.'''
|
||||
async with ctx.typing():
|
||||
arg = region.lower()
|
||||
|
||||
with ctx.typing():
|
||||
embed = cmn.embed_factory(ctx)
|
||||
if arg not in self.bandcharts:
|
||||
desc = 'Possible arguments are:\n'
|
||||
@ -39,7 +41,7 @@ class ImageCog(commands.Cog):
|
||||
embed.description = desc
|
||||
embed.colour = cmn.colours.bad
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
return
|
||||
metadata: cmn.ImageMetadata = self.bandcharts[arg]
|
||||
img = discord.File(cmn.paths.bandcharts / metadata.filename,
|
||||
filename=metadata.filename)
|
||||
@ -55,9 +57,8 @@ class ImageCog(commands.Cog):
|
||||
@commands.command(name="map", category=cmn.cat.maps)
|
||||
async def _map(self, ctx: commands.Context, map_id: str = ''):
|
||||
'''Posts an image of a ham-relevant map.'''
|
||||
async with ctx.typing():
|
||||
arg = map_id.lower()
|
||||
|
||||
with ctx.typing():
|
||||
embed = cmn.embed_factory(ctx)
|
||||
if arg not in self.maps:
|
||||
desc = 'Possible arguments are:\n'
|
||||
@ -67,7 +68,7 @@ class ImageCog(commands.Cog):
|
||||
embed.description = desc
|
||||
embed.colour = cmn.colours.bad
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
return
|
||||
metadata: cmn.ImageMetadata = self.maps[arg]
|
||||
img = discord.File(cmn.paths.maps / metadata.filename,
|
||||
filename=metadata.filename)
|
||||
@ -83,17 +84,16 @@ class ImageCog(commands.Cog):
|
||||
@commands.command(name="grayline", aliases=['greyline', 'grey', 'gray', 'gl'], category=cmn.cat.maps)
|
||||
async def _grayline(self, ctx: commands.Context):
|
||||
'''Posts a map of the current greyline, where HF propagation is the best.'''
|
||||
gl_url = ('http://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=NOAAtopo.evif'
|
||||
'&imgsize=320&dynimg=y&opt=-p&lat=&lon=&alt=&tle=&date=0&utc=&jd=')
|
||||
with ctx.typing():
|
||||
async with ctx.typing():
|
||||
embed = cmn.embed_factory(ctx)
|
||||
embed.title = 'Current Greyline Conditions'
|
||||
embed.colour = cmn.colours.good
|
||||
async with self.session.get(gl_url) as resp:
|
||||
async with self.session.get(self.gl_url) as resp:
|
||||
if resp.status != 200:
|
||||
embed.description = 'Could not download file...'
|
||||
embed.colour = cmn.colours.bad
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
return
|
||||
data = io.BytesIO(await resp.read())
|
||||
embed.set_image(url=f'attachment://greyline.jpg')
|
||||
await ctx.send(embed=embed, file=discord.File(data, 'greyline.jpg'))
|
||||
|
@ -28,7 +28,7 @@ class WeatherCog(commands.Cog):
|
||||
@commands.command(name="bandconditions", aliases=['cond', 'condx', 'conditions'], category=cmn.cat.weather)
|
||||
async def _band_conditions(self, ctx: commands.Context):
|
||||
'''Posts an image of HF Band Conditions.'''
|
||||
with ctx.typing():
|
||||
async with ctx.typing():
|
||||
embed = cmn.embed_factory(ctx)
|
||||
embed.title = 'Current Solar Conditions'
|
||||
embed.colour = cmn.colours.good
|
||||
@ -36,7 +36,8 @@ class WeatherCog(commands.Cog):
|
||||
if resp.status != 200:
|
||||
embed.description = 'Could not download file...'
|
||||
embed.colour = cmn.colours.bad
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
return
|
||||
data = io.BytesIO(await resp.read())
|
||||
embed.set_image(url=f'attachment://condx.png')
|
||||
await ctx.send(embed=embed, file=discord.File(data, 'condx.png'))
|
||||
@ -61,7 +62,7 @@ class WeatherCog(commands.Cog):
|
||||
async def _weather_conditions_forecast(self, ctx: commands.Context, *, location: str):
|
||||
'''Posts an image of Local Weather Conditions for the next three days from [wttr.in](http://wttr.in/).
|
||||
See help for weather command for possible location types. Add a `-c` or `-f` to use Celcius or Fahrenheit.'''
|
||||
with ctx.typing():
|
||||
async with ctx.typing():
|
||||
try:
|
||||
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
||||
except AttributeError:
|
||||
@ -85,7 +86,8 @@ See help for weather command for possible location types. Add a `-c` or `-f` to
|
||||
if resp.status != 200:
|
||||
embed.description = 'Could not download file...'
|
||||
embed.colour = cmn.colours.bad
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
return
|
||||
data = io.BytesIO(await resp.read())
|
||||
embed.set_image(url=f'attachment://wttr_forecast.png')
|
||||
await ctx.send(embed=embed, file=discord.File(data, 'wttr_forecast.png'))
|
||||
@ -94,7 +96,7 @@ See help for weather command for possible location types. Add a `-c` or `-f` to
|
||||
async def _weather_conditions_now(self, ctx: commands.Context, *, location: str):
|
||||
'''Posts an image of current Local Weather Conditions from [wttr.in](http://wttr.in/).
|
||||
See help for weather command for possible location types. Add a `-c` or `-f` to use Celcius or Fahrenheit.'''
|
||||
with ctx.typing():
|
||||
async with ctx.typing():
|
||||
try:
|
||||
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
||||
except AttributeError:
|
||||
@ -118,7 +120,8 @@ See help for weather command for possible location types. Add a `-c` or `-f` to
|
||||
if resp.status != 200:
|
||||
embed.description = 'Could not download file...'
|
||||
embed.colour = cmn.colours.bad
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
return
|
||||
data = io.BytesIO(await resp.read())
|
||||
embed.set_image(url=f'attachment://wttr_now.png')
|
||||
await ctx.send(embed=embed, file=discord.File(data, 'wttr_now.png'))
|
||||
|
Loading…
Reference in New Issue
Block a user