-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoniker.py
241 lines (158 loc) · 7.28 KB
/
moniker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import logging
from datetime import datetime, timezone
from os import environ
from sys import exit, stdout
from typing import Self
import dotenv
from discord_webhook import DiscordEmbed, DiscordWebhook
from httpx import ReadTimeout, TimeoutException
from loguru import logger
from loguru_discord import DiscordSink
from handlers import Intercept
from services import CashApp, GitHub, Mastodon, Snapchat, Venmo, X, YouTube
class Moniker:
"""
Monitor usernames across various services and report availability via Discord.
https://github.com/EthanC/Moniker
"""
def Start(self: Self) -> None:
"""Initialize Moniker and begin primary functionality."""
logger.info("Moniker")
logger.info("https://github.com/EthanC/Moniker")
# Reroute standard logging to Loguru
logging.basicConfig(handlers=[Intercept()], level=0, force=True)
if dotenv.load_dotenv():
logger.success("Loaded environment variables")
logger.trace(environ)
if level := environ.get("LOG_LEVEL"):
logger.remove()
logger.add(stdout, level=level)
logger.success(f"Set console logging level to {level}")
if url := environ.get("LOG_DISCORD_WEBHOOK_URL"):
logger.add(
DiscordSink(url, suppress=[ReadTimeout, TimeoutException]),
level=environ.get("LOG_DISCORD_WEBHOOK_LEVEL"),
backtrace=False,
)
logger.success(f"Enabled logging to Discord webhook")
logger.trace(url)
Moniker.CheckCashApp(self)
Moniker.CheckGitHub(self)
Moniker.CheckMastodon(self)
Moniker.CheckSnapchat(self)
Moniker.CheckVenmo(self)
Moniker.CheckX(self)
Moniker.CheckYouTube(self)
logger.success("Completed username availability checks for all services")
def CheckCashApp(self: Self) -> None:
"""Check availability of the configured Cash App $Cashtags."""
if not (var := environ.get("CASHAPP_USERNAMES")):
logger.info("Skipping Cash App, no $Cashtags configured")
return
cashtags: list[str] = var.split(",")
logger.trace(cashtags)
for cashtag in cashtags:
if not CashApp.IsUserAvailable(self, cashtag):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = CashApp.BuildEmbed(self, cashtag)
Moniker.Notify(self, url, embed)
logger.info("Completed $Cashtag availability checks for Cash App")
def CheckGitHub(self: Self) -> None:
"""Check availability of the configured GitHub usernames."""
if not (var := environ.get("GITHUB_USERNAMES")):
logger.info("Skipping GitHub, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not GitHub.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = GitHub.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for GitHub")
def CheckMastodon(self: Self) -> None:
"""Check availability of the configured Mastodon usernames."""
if not (var := environ.get("MASTODON_USERNAMES")):
logger.info("Skipping Mastodon, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not Mastodon.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = Mastodon.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for Mastodon")
def CheckSnapchat(self: Self) -> None:
"""Check availability of the configured Snapchat usernames."""
if not (var := environ.get("SNAPCHAT_USERNAMES")):
logger.info("Skipping Snapchat, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not Snapchat.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = Snapchat.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for Snapchat")
def CheckX(self: Self) -> None:
"""Check availability of the configured X usernames."""
if not (var := environ.get("X_USERNAMES")):
logger.info("Skipping X, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not X.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = X.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for X")
def CheckVenmo(self: Self) -> None:
"""Check availability of the configured Venmo usernames."""
if not (var := environ.get("VENMO_USERNAMES")):
logger.info("Skipping Venmo, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not Venmo.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = Venmo.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for Venmo")
def CheckYouTube(self: Self) -> None:
"""Check availability of the configured YouTube usernames."""
if not (var := environ.get("YOUTUBE_USERNAMES")):
logger.info("Skipping YouTube, no usernames configured")
return
usernames: list[str] = var.split(",")
logger.trace(usernames)
for username in usernames:
if not YouTube.IsUserAvailable(self, username):
continue
if url := environ.get("DISCORD_WEBHOOK_URL"):
embed: DiscordEmbed = YouTube.BuildEmbed(self, username)
Moniker.Notify(self, url, embed)
logger.info("Completed username availability checks for YouTube")
def Notify(self: Self, url: str, embed: DiscordEmbed) -> None:
"""Report username availability to the configured Discord webhook."""
embed.set_author(
"Moniker",
url="https://github.com/EthanC/Moniker",
icon_url="https://i.imgur.com/gImd2zu.png",
)
embed.set_timestamp(datetime.now(timezone.utc).timestamp())
DiscordWebhook(url=url, embeds=[embed], rate_limit_retry=True).execute()
if __name__ == "__main__":
try:
Moniker.Start(Moniker)
except KeyboardInterrupt:
exit()