stopforumspam-checker.py
· 1.2 KiB · Python
原始檔案
# The amount of days within which to check if the user was reported
LAST_SEEN_THRESHOLD = 180
LAST_SEEN_REGEX = r"<lastseen>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})<\/lastseen>"
# The contact name to use in rejection messages
CONTACT = "Admin at admin@example.com"
from datetime import datetime
import requests
import re
prompt_data = request.context.get("prompt_data")
if 'email' in prompt_data:
req_url = f"http://api.stopforumspam.org/api?email={prompt_data['email']}"
if 'username' in prompt_data:
req_url += f"&username={prompt_data['username']}"
resp = requests.get(req_url)
if resp.status_code != 200:
ak_message(f"There was an error creating your account. Please contact {CONTACT} with the following details: SFS HTTP Error {resp.status_code}")
return False
matches = re.search(LAST_SEEN_REGEX, resp.text)
if matches is None:
return True
last_seen = datetime.strptime(matches.group(1), '%Y-%m-%d %H:%M:%S')
time_elapsed = datetime.now() - last_seen
if time_elapsed.days < LAST_SEEN_THRESHOLD:
ak_message(f"Sorry, we cannot approve your account at this time. Please come back later or contact {CONTACT} if the issue persists.")
return False
return True
1 | # The amount of days within which to check if the user was reported |
2 | LAST_SEEN_THRESHOLD = 180 |
3 | LAST_SEEN_REGEX = r"<lastseen>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})<\/lastseen>" |
4 | |
5 | # The contact name to use in rejection messages |
6 | CONTACT = "Admin at admin@example.com" |
7 | |
8 | from datetime import datetime |
9 | import requests |
10 | import re |
11 | |
12 | prompt_data = request.context.get("prompt_data") |
13 | |
14 | if 'email' in prompt_data: |
15 | req_url = f"http://api.stopforumspam.org/api?email={prompt_data['email']}" |
16 | if 'username' in prompt_data: |
17 | req_url += f"&username={prompt_data['username']}" |
18 | |
19 | resp = requests.get(req_url) |
20 | |
21 | if resp.status_code != 200: |
22 | ak_message(f"There was an error creating your account. Please contact {CONTACT} with the following details: SFS HTTP Error {resp.status_code}") |
23 | return False |
24 | |
25 | matches = re.search(LAST_SEEN_REGEX, resp.text) |
26 | if matches is None: |
27 | return True |
28 | |
29 | last_seen = datetime.strptime(matches.group(1), '%Y-%m-%d %H:%M:%S') |
30 | time_elapsed = datetime.now() - last_seen |
31 | if time_elapsed.days < LAST_SEEN_THRESHOLD: |
32 | ak_message(f"Sorry, we cannot approve your account at this time. Please come back later or contact {CONTACT} if the issue persists.") |
33 | return False |
34 | |
35 | return True |
36 |