Skip to content

Commit

Permalink
Add apprise notification on login with phone code (#229)
Browse files Browse the repository at this point in the history
Send an Apprise notification when receiving a code to validate with
Microsoft Authentificator.

This allows users to run the bot in the background, even if they aren't
connected/their session expires.
Also convenient if you're not paying attention to the terminal and have
phone notifications muted.

Example:

![image](https://github.com/user-attachments/assets/8b3bb2b0-74fe-4f97-b5c1-17766fe3dc0b)
  • Loading branch information
cal4 authored Dec 1, 2024
2 parents 2e2540c + b6ee600 commit c269afb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ apprise:
ignore-safeguard-info: True
uncaught-exception:
enabled: True # True or False
login-code:
enabled: True # True or False
summary: ON_ERROR
default:
geolocation: US # Replace with your country code https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Expand Down
17 changes: 17 additions & 0 deletions src/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from undetected_chromedriver import Chrome

from src.browser import Browser
from src.utils import sendNotification, CONFIG


class Login:
Expand Down Expand Up @@ -101,6 +102,14 @@ def execute_login(self) -> None:
"[LOGIN] Confirm your login with code %s on your phone (you have one minute)!\a",
codeField.text,
)
if (
CONFIG.get("apprise")
.get("notify")
.get("login-code")
.get("enabled")
):
sendNotification(
f"Confirm your login on your phone", f"Code: {codeField.text} (expires in 1 minute)")
self.utils.waitUntilVisible(By.NAME, "kmsiForm", 60)
logging.info("[LOGIN] Successfully verified!")
else:
Expand Down Expand Up @@ -140,6 +149,14 @@ def execute_login(self) -> None:
" one minute)!\a",
codeField.text,
)
if (
CONFIG.get("apprise")
.get("notify")
.get("login-code")
.get("enabled")
):
sendNotification(
f"Confirm your login on your phone", f"Code: {codeField.text} (expires in 1 minute)")
self.utils.waitUntilVisible(By.NAME, "kmsiForm", 60)
logging.info("[LOGIN] Successfully verified!")

Expand Down
1 change: 1 addition & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"notify": {
"incomplete-activity": {"enabled": True, "ignore-safeguard-info": True},
"uncaught-exception": {"enabled": True},
"login-code": {"enabled": True},
},
"summary": "ON_ERROR",
},
Expand Down

0 comments on commit c269afb

Please sign in to comment.