Skip to content

Commit

Permalink
Some formating and error bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticuproject committed Sep 3, 2024
1 parent c89fe96 commit 7c8a2e6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=13 --max-line-length=127 --statistics
flake8 . --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM python:3.11-alpine

RUN apk --no-cache add curl
RUN adduser -D bot
USER bot
WORKDIR /home/bot
Expand Down
58 changes: 43 additions & 15 deletions pwned_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def split_search(embed: discord.Embed, domain_list: list[dict[str, str]],
send_list.append(domain_list[i])
for item in send_list:
for k, v in item.items():
embed.add_field(name=k, value=v, inline=False)
embed.add_field(name=k, value=v, inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=True)


def cleanhtml(raw_html: str) -> str:
Expand Down Expand Up @@ -151,7 +152,12 @@ async def password(ctx: commands.Context[commands.Bot], *args: str) -> None:
breach_num = pwned(default_account, app_name,
api_key).search_password(paswd)

if int(breach_num) > 0:
if int(breach_num) == 429:
result = ("Your password has either been compromised and "
"found 429 time in the database, or "
"this request is rate limited. I am too lazy "
"to fix this to tell the difference.")
if int(breach_num) > 0 and int(breach_num) != 429:
result = ("Your password has been compromised. "
f"It was found {breach_num} times in the database.")
await ctx.send(file=discord.File("images/warning-sign.png"))
Expand Down Expand Up @@ -193,12 +199,16 @@ async def search(ctx: commands.Context[commands.Bot], *args: str) -> None:
domain_list: list[dict[str, str]] = []
result = pwned(email, app_name, api_key).search_all_breaches()

if isinstance(result, list):
if isinstance(result, list) and result:
breach_num = len(result)
elif isinstance(result, int) and result == 429:
error = "Rate limit exceeded. Wait a few minutes."
await ctx.send(error)
raise RequestException
else:
raise TypeError

mod = breach_num % 20
mod = breach_num % 5
num_txt = (f"Your account was found in {breach_num} "
"database breaches.\nThose breaches are:")
await ctx.send(file=discord.File("images/warning-sign.png"))
Expand All @@ -215,10 +225,10 @@ async def search(ctx: commands.Context[commands.Bot], *args: str) -> None:
name_value, (str, int)) else "Unknown"
domain_list.append({"Name": name, "Domain": domain})

for i in range(breach_num // 20):
if i * 20 < breach_num:
for i in range(breach_num // 5):
if i * 5 < breach_num:
embed = discord.Embed()
split_search(embed, domain_list, i * 20, (i * 20) + 20)
split_search(embed, domain_list, i * 5, (i * 5) + 5)
await ctx.send(embed=embed)

if mod > 0:
Expand Down Expand Up @@ -260,6 +270,10 @@ async def breaches(ctx: commands.Context[commands.Bot]) -> None:

if isinstance(result, list):
breach_num = len(result)
elif isinstance(result, int) and result == 429:
error = "Rate limit exceeded. Wait a few minutes."
await ctx.send(error)
raise RequestException
else:
raise RequestException

Expand Down Expand Up @@ -314,8 +328,12 @@ async def breach_name(ctx: commands.Context[commands.Bot], *args: str) -> None:
result_list = pwned(default_account, app_name,
api_key).single_breach(name=site_name)

if isinstance(result_list, list):
if isinstance(result_list, list) and result_list:
result = result_list[0]
elif isinstance(result_list, int) and result_list == 429:
error = "Rate limit exceeded. Wait a few minutes."
await ctx.send(error)
raise RequestException
else:
raise TypeError

Expand Down Expand Up @@ -399,12 +417,16 @@ async def pastes(ctx: commands.Context[commands.Bot], *args: str) -> None:
email = args[0]
result = pwned(email, app_name, api_key).search_pastes()

if isinstance(result, list):
if isinstance(result, list) and result:
breach_num = len(result)
elif isinstance(result, int) and result == 429:
error = "Rate limit exceeded. Wait a few minutes."
await ctx.send(error)
raise RequestException
else:
raise TypeError

mod = breach_num % 20
mod = breach_num % 5
num_txt = f"Your account was found in {breach_num} pastes."
await ctx.send(file=discord.File("images/warning-sign.png"))
await ctx.send(num_txt)
Expand All @@ -416,14 +438,14 @@ async def pastes(ctx: commands.Context[commands.Bot], *args: str) -> None:
if title is None:
title = "No Title"

paste_id_value: str | int | bool = data.get("ID", "Unknown")
paste_id_value: str | int | bool = data.get("Id", "Unknown")
paste_id_str = str(paste_id_value)
title_str = str(title)
names.append({"Title": title_str, "ID": paste_id_str})
names.append({"Title": title_str, "Id": paste_id_str})

for i in range(breach_num // 20):
if i * 20 < breach_num:
split_search(embed, names, i * 20, (i * 20) + 20)
for i in range(breach_num // 5):
if i * 5 < breach_num:
split_search(embed, names, i * 5, (i * 5) + 5)
await ctx.send(embed=embed)

if mod > 0:
Expand Down Expand Up @@ -476,6 +498,12 @@ async def paste_id(ctx: commands.Context[commands.Bot], *args: str) -> None:
if data["Id"] == i_d:
for key, value in data.items():
embed.add_field(name=key, value=value, inline=False)
elif isinstance(result, int) and result == 429:
error = "Rate limit exceeded. Wait a few minutes."
await ctx.send(error)
raise RequestException
else:
raise TypeError

await ctx.send(embed=embed)
await ctx.send("*All data sourced from https://haveibeenpwned.com*")
Expand Down

0 comments on commit 7c8a2e6

Please sign in to comment.