mirror of
https://github.com/miaowware/qrm2.git
synced 2024-09-27 14:26:35 -04:00
Validate inputs for ?ae7q and ?qrz commands
This commit is contained in:
parent
eb98e295d2
commit
4ab4748b9f
42
exts/ae7q.py
42
exts/ae7q.py
@ -16,6 +16,8 @@ the GNU General Public License, version 2.
|
|||||||
# KC4USA: reserved, no call history, *but* has application history
|
# KC4USA: reserved, no call history, *but* has application history
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
@ -44,6 +46,14 @@ class AE7QCog(commands.Cog):
|
|||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
|
|
||||||
|
if not re.match('[A-Z0-9]+$', callsign):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "AE7Q History for Callsign"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid callsign!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
async with self.session.get(base_url + callsign) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise cmn.BotHTTPError(resp)
|
raise cmn.BotHTTPError(resp)
|
||||||
@ -110,6 +120,14 @@ class AE7QCog(commands.Cog):
|
|||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
|
|
||||||
|
if not re.match('[A-Z0-9]+$', callsign):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "AE7Q Trustee History for Callsign"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid callsign!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
async with self.session.get(base_url + callsign) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise cmn.BotHTTPError(resp)
|
raise cmn.BotHTTPError(resp)
|
||||||
@ -178,6 +196,14 @@ class AE7QCog(commands.Cog):
|
|||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
|
|
||||||
|
if not re.match('[A-Z0-9]+$', callsign):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "AE7Q Application History for Callsign"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid callsign!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
async with self.session.get(base_url + callsign) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise cmn.BotHTTPError(resp)
|
raise cmn.BotHTTPError(resp)
|
||||||
@ -250,6 +276,14 @@ class AE7QCog(commands.Cog):
|
|||||||
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
|
|
||||||
|
if not re.match('[0-9]+$', frn):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "AE7Q History for FRN"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid FRN!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
async with self.session.get(base_url + frn) as resp:
|
async with self.session.get(base_url + frn) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise cmn.BotHTTPError(resp)
|
raise cmn.BotHTTPError(resp)
|
||||||
@ -313,6 +347,14 @@ class AE7QCog(commands.Cog):
|
|||||||
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
|
|
||||||
|
if not re.match('[A-Z][0-9]+$', licensee_id, re.IGNORECASE):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "AE7Q History for Licensee"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid licensee ID!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
async with self.session.get(base_url + licensee_id) as resp:
|
async with self.session.get(base_url + licensee_id) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise cmn.BotHTTPError(resp)
|
raise cmn.BotHTTPError(resp)
|
||||||
|
@ -9,6 +9,7 @@ the GNU General Public License, version 2.
|
|||||||
|
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import re
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -31,6 +32,14 @@ class QRZCog(commands.Cog):
|
|||||||
"""Looks up a callsign on [QRZ.com](https://www.qrz.com/). Add `--link` to only link the QRZ page."""
|
"""Looks up a callsign on [QRZ.com](https://www.qrz.com/). Add `--link` to only link the QRZ page."""
|
||||||
flags = [f.lower() for f in flags]
|
flags = [f.lower() for f in flags]
|
||||||
|
|
||||||
|
if not re.match('[A-Z0-9]+$', callsign, re.IGNORECASE):
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
embed.title = "QRZ Data for Callsign"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
embed.description = "Not a valid callsign!"
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
if keys.qrz_user == "" or keys.qrz_pass == "" or "--link" in flags:
|
if keys.qrz_user == "" or keys.qrz_pass == "" or "--link" in flags:
|
||||||
await ctx.send(f"http://qrz.com/db/{callsign}")
|
await ctx.send(f"http://qrz.com/db/{callsign}")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user