parent
a08367335e
commit
d7289a2189
|
@ -8,7 +8,7 @@ client = SPBClient()
|
|||
|
||||
async def main():
|
||||
# calling for status
|
||||
user = input("Enter a Username or UserID to check Spam Prediction on SPB: ")
|
||||
user = input("Enter a Username or UserID: ")
|
||||
status = await client.check_blacklist(user)
|
||||
# check if status got a successful response
|
||||
if status.success:
|
||||
|
@ -18,12 +18,20 @@ async def main():
|
|||
|
||||
|
||||
async def text_parser(status: Blacklist):
|
||||
text = "Private TelegramID: {}\n".format(status.private_telegram_id)
|
||||
text = "Private TelegramID: {}\n".format(
|
||||
status.private_telegram_id
|
||||
)
|
||||
text += "Entity Type: {}\n".format(status.entity_type)
|
||||
if status.attributes.is_blacklisted:
|
||||
text += "Blacklist Flag: {}\n".format(status.attributes.blacklist_flag)
|
||||
text += "Blacklist Reason: {}\n".format(status.attributes.blacklist_reason)
|
||||
text += "Original PrivateID: {}\n".format(status.attributes.original_private_id)
|
||||
text += "Blacklist Flag: {}\n".format(
|
||||
status.attributes.blacklist_flag
|
||||
)
|
||||
text += "Blacklist Reason: {}\n".format(
|
||||
status.attributes.blacklist_reason
|
||||
)
|
||||
text += "Original PrivateID: {}\n".format(
|
||||
status.attributes.original_private_id
|
||||
)
|
||||
if status.attributes.is_potential_spammer:
|
||||
text += "This user is a Spammer\n"
|
||||
if status.attributes.is_operator:
|
||||
|
@ -36,11 +44,21 @@ async def text_parser(status: Blacklist):
|
|||
text += "This user is an Intellivoid Verified Account\n"
|
||||
if status.attributes.is_official:
|
||||
text += "This is an Official Account\n"
|
||||
text += "Language: {}\n".format(status.language_prediction.language)
|
||||
text += "Language Probability: {}\n".format(status.language_prediction.probability)
|
||||
text += "Ham Prediction: {}\n".format(status.spam_prediction.ham_prediction)
|
||||
text += "Spam Prediction: {}\n".format(status.spam_prediction.spam_prediction)
|
||||
text += "Last Updated On: {}\n".format(status.last_updated)
|
||||
text += "Language: {}\n".format(
|
||||
status.language_prediction.language
|
||||
)
|
||||
text += "Language Probability: {}\n".format(
|
||||
status.language_prediction.probability
|
||||
)
|
||||
text += "Ham Prediction: {}\n".format(
|
||||
status.spam_prediction.ham_prediction
|
||||
)
|
||||
text += "Spam Prediction: {}\n".format(
|
||||
status.spam_prediction.spam_prediction
|
||||
)
|
||||
text += "Last Updated On: {}\n".format(
|
||||
status.last_updated
|
||||
)
|
||||
return text
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ client = SPBClient()
|
|||
|
||||
def main():
|
||||
# calling for status
|
||||
user = input("Enter a Username or UserID to check Spam Prediction on SPB: ")
|
||||
user = input("Enter a Username or UserID: ")
|
||||
status = client.check_blacklist(user)
|
||||
# check if status got a successful response
|
||||
if status.success:
|
||||
|
@ -17,12 +17,22 @@ def main():
|
|||
|
||||
|
||||
def text_parser(status: Blacklist):
|
||||
text = "Private TelegramID: {}\n".format(status.private_telegram_id)
|
||||
text += "Entity Type: {}\n".format(status.entity_type)
|
||||
text = "Private TelegramID: {}\n".format(
|
||||
status.private_telegram_id
|
||||
)
|
||||
text += "Entity Type: {}\n".format(
|
||||
status.entity_type
|
||||
)
|
||||
if status.attributes.is_blacklisted:
|
||||
text += "Blacklist Flag: {}\n".format(status.attributes.blacklist_flag)
|
||||
text += "Blacklist Reason: {}\n".format(status.attributes.blacklist_reason)
|
||||
text += "Original PrivateID: {}\n".format(status.attributes.original_private_id)
|
||||
text += "Blacklist Flag: {}\n".format(
|
||||
status.attributes.blacklist_flag
|
||||
)
|
||||
text += "Blacklist Reason: {}\n".format(
|
||||
status.attributes.blacklist_reason
|
||||
)
|
||||
text += "Original PrivateID: {}\n".format(
|
||||
status.attributes.original_private_id
|
||||
)
|
||||
if status.attributes.is_potential_spammer:
|
||||
text += "This user is a Spammer\n"
|
||||
if status.attributes.is_operator:
|
||||
|
@ -35,11 +45,21 @@ def text_parser(status: Blacklist):
|
|||
text += "This user is an Intellivoid Verified Account\n"
|
||||
if status.attributes.is_official:
|
||||
text += "This is an Official Account\n"
|
||||
text += "Language: {}\n".format(status.language_prediction.language)
|
||||
text += "Language Probability: {}\n".format(status.language_prediction.probability)
|
||||
text += "Ham Prediction: {}\n".format(status.spam_prediction.ham_prediction)
|
||||
text += "Spam Prediction: {}\n".format(status.spam_prediction.spam_prediction)
|
||||
text += "Last Updated On: {}\n".format(status.last_updated)
|
||||
text += "Language: {}\n".format(
|
||||
status.language_prediction.language
|
||||
)
|
||||
text += "Language Probability: {}\n".format(
|
||||
status.language_prediction.probability
|
||||
)
|
||||
text += "Ham Prediction: {}\n".format(
|
||||
status.spam_prediction.ham_prediction
|
||||
)
|
||||
text += "Spam Prediction: {}\n".format(
|
||||
status.spam_prediction.spam_prediction
|
||||
)
|
||||
text += "Last Updated On: {}\n".format(
|
||||
status.last_updated
|
||||
)
|
||||
return text
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""Initial Directory."""
|
||||
from .client import SPBClient # noqa: F401
|
||||
|
||||
__version__ = "0.0.4"
|
||||
|
|
|
@ -8,11 +8,24 @@ from .types import Blacklist
|
|||
|
||||
class SPBClient:
|
||||
def __init__(
|
||||
self, *, host: str = "https://api.intellivoid.net/spamprotection/v1/lookup"
|
||||
self,
|
||||
*,
|
||||
host: str = "https://api.intellivoid.net/spamprotection/v1/lookup"
|
||||
) -> None:
|
||||
self._host = host
|
||||
|
||||
async def do_request(self, user_id: str, method: str = "get"):
|
||||
async def do_request(
|
||||
self,
|
||||
user_id: str,
|
||||
):
|
||||
"""[Requests to the url]
|
||||
|
||||
Args:
|
||||
user_id (str): [username or user_id can be passed into the arg]
|
||||
|
||||
Returns:
|
||||
[json]: [json response of the output]
|
||||
"""
|
||||
async with aiohttp.ClientSession() as ses:
|
||||
request = await ses.get(f"{self._host}?query={user_id}")
|
||||
try:
|
||||
|
@ -20,14 +33,36 @@ class SPBClient:
|
|||
except JSONDecodeError:
|
||||
return await request.text(), request
|
||||
|
||||
async def raw_output(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
async def raw_output(
|
||||
self,
|
||||
user_id: Union[int, str]
|
||||
):
|
||||
"""[raw json output]
|
||||
|
||||
Args:
|
||||
user_id (Union[int, str]): [can pass user_id or username]
|
||||
|
||||
Returns:
|
||||
[json]: [returns json response]
|
||||
"""
|
||||
try:
|
||||
data, _ = await self.do_request(user_id)
|
||||
return data
|
||||
except UnknownError:
|
||||
return False
|
||||
|
||||
async def check_blacklist(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
async def check_blacklist(
|
||||
self,
|
||||
user_id: Union[int, str]
|
||||
) -> Union[Blacklist, bool]:
|
||||
"""[checks spb for blacklist]
|
||||
|
||||
Args:
|
||||
user_id (Union[int, str]): [can pass user_id or username]
|
||||
|
||||
Returns:
|
||||
Union[Blacklist, bool]: [Blacklist type]
|
||||
"""
|
||||
try:
|
||||
data, _ = await self.do_request(user_id)
|
||||
return Blacklist(**data)
|
||||
|
|
|
@ -9,25 +9,60 @@ from typing import Union
|
|||
|
||||
class SPBClient:
|
||||
def __init__(
|
||||
self, *, host: str = "https://api.intellivoid.net/spamprotection/v1/lookup"
|
||||
self,
|
||||
*,
|
||||
host: str = "https://api.intellivoid.net/spamprotection/v1/lookup"
|
||||
) -> None:
|
||||
self._host = host
|
||||
|
||||
def do_request(self, user_id: str, method: str = "get"):
|
||||
def do_request(
|
||||
self,
|
||||
user_id: str,
|
||||
):
|
||||
"""[Requests to the url]
|
||||
|
||||
Args:
|
||||
user_id (str): [username or user_id can be passed into the arg]
|
||||
|
||||
Returns:
|
||||
[json]: [json response of the output]
|
||||
"""
|
||||
request = requests.get(f"{self._host}?query={user_id}")
|
||||
try:
|
||||
return request.json(), request
|
||||
except JSONDecodeError:
|
||||
return request.text(), request
|
||||
|
||||
def raw_output(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
def raw_output(
|
||||
self,
|
||||
user_id: Union[int, str]
|
||||
):
|
||||
"""[raw json output]
|
||||
|
||||
Args:
|
||||
user_id (Union[int, str]): [can pass user_id or username]
|
||||
|
||||
Returns:
|
||||
[json]: [returns json response]
|
||||
"""
|
||||
try:
|
||||
data, _ = self.do_request(user_id)
|
||||
return data
|
||||
except UnknownError:
|
||||
return False
|
||||
|
||||
def check_blacklist(self, user_id: Union[int, str]) -> Union[Blacklist, bool]:
|
||||
def check_blacklist(
|
||||
self,
|
||||
user_id: Union[int, str]
|
||||
) -> Union[Blacklist, bool]:
|
||||
"""[checks spb for blacklist]
|
||||
|
||||
Args:
|
||||
user_id (Union[int, str]): [can pass user_id or username]
|
||||
|
||||
Returns:
|
||||
Union[Blacklist, bool]: [Blacklist type]
|
||||
"""
|
||||
try:
|
||||
data, _ = self.do_request(user_id)
|
||||
return Blacklist(**data)
|
||||
|
|
|
@ -11,7 +11,13 @@ class SPB:
|
|||
|
||||
|
||||
class Blacklist(SPB):
|
||||
def __init__(self, success: bool, response_code: int, results=dict, **kwargs):
|
||||
def __init__(
|
||||
self,
|
||||
success: bool,
|
||||
response_code: int,
|
||||
results=dict,
|
||||
**kwargs
|
||||
):
|
||||
self.success = success
|
||||
self.response_code = response_code
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue