mirror of
https://github.com/miaowware/qrm2.git
synced 2025-05-31 13:42:34 -04: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):
|
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):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.bandcharts = cmn.ImagesGroup(cmn.paths.bandcharts / "meta.json")
|
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)
|
@commands.command(name="bandplan", aliases=['plan', 'bands'], category=cmn.cat.ref)
|
||||||
async def _bandplan(self, ctx: commands.Context, region: str = ''):
|
async def _bandplan(self, ctx: commands.Context, region: str = ''):
|
||||||
'''Posts an image of Frequency Allocations.'''
|
'''Posts an image of Frequency Allocations.'''
|
||||||
|
async with ctx.typing():
|
||||||
arg = region.lower()
|
arg = region.lower()
|
||||||
|
|
||||||
with ctx.typing():
|
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
if arg not in self.bandcharts:
|
if arg not in self.bandcharts:
|
||||||
desc = 'Possible arguments are:\n'
|
desc = 'Possible arguments are:\n'
|
||||||
@ -39,7 +41,7 @@ class ImageCog(commands.Cog):
|
|||||||
embed.description = desc
|
embed.description = desc
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
else:
|
return
|
||||||
metadata: cmn.ImageMetadata = self.bandcharts[arg]
|
metadata: cmn.ImageMetadata = self.bandcharts[arg]
|
||||||
img = discord.File(cmn.paths.bandcharts / metadata.filename,
|
img = discord.File(cmn.paths.bandcharts / metadata.filename,
|
||||||
filename=metadata.filename)
|
filename=metadata.filename)
|
||||||
@ -55,9 +57,8 @@ class ImageCog(commands.Cog):
|
|||||||
@commands.command(name="map", category=cmn.cat.maps)
|
@commands.command(name="map", category=cmn.cat.maps)
|
||||||
async def _map(self, ctx: commands.Context, map_id: str = ''):
|
async def _map(self, ctx: commands.Context, map_id: str = ''):
|
||||||
'''Posts an image of a ham-relevant map.'''
|
'''Posts an image of a ham-relevant map.'''
|
||||||
|
async with ctx.typing():
|
||||||
arg = map_id.lower()
|
arg = map_id.lower()
|
||||||
|
|
||||||
with ctx.typing():
|
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
if arg not in self.maps:
|
if arg not in self.maps:
|
||||||
desc = 'Possible arguments are:\n'
|
desc = 'Possible arguments are:\n'
|
||||||
@ -67,7 +68,7 @@ class ImageCog(commands.Cog):
|
|||||||
embed.description = desc
|
embed.description = desc
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
else:
|
return
|
||||||
metadata: cmn.ImageMetadata = self.maps[arg]
|
metadata: cmn.ImageMetadata = self.maps[arg]
|
||||||
img = discord.File(cmn.paths.maps / metadata.filename,
|
img = discord.File(cmn.paths.maps / metadata.filename,
|
||||||
filename=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)
|
@commands.command(name="grayline", aliases=['greyline', 'grey', 'gray', 'gl'], category=cmn.cat.maps)
|
||||||
async def _grayline(self, ctx: commands.Context):
|
async def _grayline(self, ctx: commands.Context):
|
||||||
'''Posts a map of the current greyline, where HF propagation is the best.'''
|
'''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'
|
async with ctx.typing():
|
||||||
'&imgsize=320&dynimg=y&opt=-p&lat=&lon=&alt=&tle=&date=0&utc=&jd=')
|
|
||||||
with ctx.typing():
|
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
embed.title = 'Current Greyline Conditions'
|
embed.title = 'Current Greyline Conditions'
|
||||||
embed.colour = cmn.colours.good
|
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:
|
if resp.status != 200:
|
||||||
embed.description = 'Could not download file...'
|
embed.description = 'Could not download file...'
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
else:
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
data = io.BytesIO(await resp.read())
|
data = io.BytesIO(await resp.read())
|
||||||
embed.set_image(url=f'attachment://greyline.jpg')
|
embed.set_image(url=f'attachment://greyline.jpg')
|
||||||
await ctx.send(embed=embed, file=discord.File(data, '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)
|
@commands.command(name="bandconditions", aliases=['cond', 'condx', 'conditions'], category=cmn.cat.weather)
|
||||||
async def _band_conditions(self, ctx: commands.Context):
|
async def _band_conditions(self, ctx: commands.Context):
|
||||||
'''Posts an image of HF Band Conditions.'''
|
'''Posts an image of HF Band Conditions.'''
|
||||||
with ctx.typing():
|
async with ctx.typing():
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
embed.title = 'Current Solar Conditions'
|
embed.title = 'Current Solar Conditions'
|
||||||
embed.colour = cmn.colours.good
|
embed.colour = cmn.colours.good
|
||||||
@ -36,7 +36,8 @@ class WeatherCog(commands.Cog):
|
|||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
embed.description = 'Could not download file...'
|
embed.description = 'Could not download file...'
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
else:
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
data = io.BytesIO(await resp.read())
|
data = io.BytesIO(await resp.read())
|
||||||
embed.set_image(url=f'attachment://condx.png')
|
embed.set_image(url=f'attachment://condx.png')
|
||||||
await ctx.send(embed=embed, file=discord.File(data, '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):
|
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/).
|
'''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.'''
|
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:
|
try:
|
||||||
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
||||||
except AttributeError:
|
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:
|
if resp.status != 200:
|
||||||
embed.description = 'Could not download file...'
|
embed.description = 'Could not download file...'
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
else:
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
data = io.BytesIO(await resp.read())
|
data = io.BytesIO(await resp.read())
|
||||||
embed.set_image(url=f'attachment://wttr_forecast.png')
|
embed.set_image(url=f'attachment://wttr_forecast.png')
|
||||||
await ctx.send(embed=embed, file=discord.File(data, '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):
|
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/).
|
'''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.'''
|
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:
|
try:
|
||||||
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
units_arg = re.search(self.wttr_units_regex, location).group(1)
|
||||||
except AttributeError:
|
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:
|
if resp.status != 200:
|
||||||
embed.description = 'Could not download file...'
|
embed.description = 'Could not download file...'
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
else:
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
data = io.BytesIO(await resp.read())
|
data = io.BytesIO(await resp.read())
|
||||||
embed.set_image(url=f'attachment://wttr_now.png')
|
embed.set_image(url=f'attachment://wttr_now.png')
|
||||||
await ctx.send(embed=embed, file=discord.File(data, 'wttr_now.png'))
|
await ctx.send(embed=embed, file=discord.File(data, 'wttr_now.png'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user