This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
69 lines (57 loc) · 2.42 KB
/
main.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
import os
import json
import requests
import discord
from discord import app_commands
from dotenv import load_dotenv
from yarl import URL
load_dotenv()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
SMR_GUILD_ID = 463457129588850699
client = discord.Client(application_id="785933469531504690", intents=discord.Intents.all())
tree = app_commands.CommandTree(client)
def checklist(url):
try:
r = requests.get("https://api.stopmodreposts.org/sites.txt")
if r.status_code != 200:
return f"⚠️ Failed with status code {r.status_code}"
except ConnectionError:
return "⚠️ Connection failed"
if url in r.text:
return True
else:
return False
@tree.command(name="check", description="Check if a site is listed")
async def check(interaction: discord.Interaction, url: str):
url = URL(url).host.replace("http://", "").replace("https://", "").replace("www.", "")
# List status
list_status = checklist(url)
if type(list_status) != bool:
await interaction.response.send_message(f"List Error: {list_status}")
elif list_status is False:
await interaction.response.send_message(f"❌ **{url}** is not on our list")
elif list_status is True:
await interaction.response.send_message(f"✅ **{url}** is on our list")
@tree.command(name="submit", description="Submit a site for review")
async def submit(interaction: discord.Interaction, url: str, description: str):
url = URL(url).host.replace("http://", "").replace("https://", "").replace("www.", "")
data = {
"domain": url,
"description": f"VIA DC - {description}"
}
try:
r = requests.post("https://report.stopmodreposts.org/api/v1/report?falsepositive=false", json=data)
except ConnectionError:
return "⚠️ Connection failed"
res = json.loads(r.text)
if r.status_code == 201:
await interaction.response.send_message(f"✅ **{url}** reported! Thanks!")
elif r.status_code == 409 or r.status_code == 400:
await interaction.response.send_message(f"⚠️ Failed to report **{url}**!\nDetail: `{res['detail']}`")
else:
await interaction.response.send_message(f"⚠️ Failed with status code {r.status_code}")
async def main():
async with client:
await tree.sync(guild=SMR_GUILD_ID)
await client.start(DISCORD_TOKEN)
client.run(DISCORD_TOKEN)