|
|
@ -0,0 +1,49 @@ |
|
|
|
import asyncio |
|
|
|
import typing as T |
|
|
|
from hexbear import v1 as api |
|
|
|
|
|
|
|
async def autoban_spam( |
|
|
|
spam_ban_reasons: dict[str, T.Optional[str]], |
|
|
|
jwt_token: str |
|
|
|
): |
|
|
|
"""Run to monitor comments for known spam, remove the spam, and autoban the user""" |
|
|
|
print("Spam Automod reporting for duty") |
|
|
|
async for comment_response in api.ws.stream_all_comments(): |
|
|
|
comment = comment_response.comment |
|
|
|
if comment.content in spam_ban_reasons: |
|
|
|
|
|
|
|
# Reply with PPB |
|
|
|
request = api.comment.CreateCommentRequest( |
|
|
|
content=':ppb:', |
|
|
|
parent_id=comment.id, |
|
|
|
post_id=comment.post_id, |
|
|
|
form_id=None, |
|
|
|
auth=jwt_token, |
|
|
|
) |
|
|
|
response = await api.comment.create(request) |
|
|
|
if response.is_ok(): |
|
|
|
print(f"{comment.creator_name} got PPB'd") |
|
|
|
else: |
|
|
|
print(f"Failed to PPB {comment.creator_name}") |
|
|
|
print(response) |
|
|
|
|
|
|
|
# Siteban |
|
|
|
default_reason = "Spam Automod" |
|
|
|
reason = spam_ban_reasons.get( |
|
|
|
comment.content, |
|
|
|
default=default_reason |
|
|
|
) |
|
|
|
reason = reason if reason is not None else default_reason |
|
|
|
request = api.user.BanUserRequest( |
|
|
|
user_id=comment.user_id, |
|
|
|
ban=True, |
|
|
|
auth=jwt_token, |
|
|
|
reason=reason |
|
|
|
) |
|
|
|
response = await api.user.ban(request) |
|
|
|
if response.is_ok(): |
|
|
|
print(f"{comment.creator_name} was banned") |
|
|
|
else: |
|
|
|
print(f"Failed to ban {comment.creator_name}") |
|
|
|
print(response) |
|
|
|
print("Spam Automod logging off o7") |