-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.py
94 lines (82 loc) · 3.51 KB
/
client.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
import discord, os , dotenv, json
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print('PROTect has connected to Discord.')
for guild in client.guilds:
path = "servers/" + str(guild.id) + ".json"
print(path)
try:
# os.mkdir(path)
data = {
"flags": ["badword"],
"urls": {
"ABC": "left leaning bias",
"AlterNet": "strong left bias",
"Associated Press": "no bias",
"Axios": "no bias",
"BBC": "no bias",
"Bloomberg": "left leaning bias",
"Breitbart": "strong right bias",
"Buzzfeed": "strong left bias",
"CBS": "left leaning bias",
"CNN": "strong left bias",
"DailyMail": "strong right bias",
"Forbes": "no bias",
"FoxNews": "strong right bias",
"HuffPost": "strong left bias",
"MSNBC": "strong left bias",
"NationalReview": "strong right bias",
"NBC": "left leaning bias",
"Reuters": "no bias",
"DailyWire": "strong right bias",
"EpochTimes": "right leaning bias",
"Federalist": "strong right bias",
"Vox": "strong left bias"
},
"suggestedFlags": [],
"suggestedFlagURLs": [],
}
# path = path + "/settings.json"
# os.mkdir(path)
f = open(path, 'x')
f = open(path, 'w')
json.dump(data, f)
except FileExistsError:
path = "servers/" + str(guild.id) + "/settings.json"
@client.event
async def on_message(message):
msg_content = message.content.lower()
print(msg_content)
path = "servers/" + str(message.guild.id) + ".json"
data = json.load(open(path, 'r'))
flags = data['flags']
if any(flag in msg_content for flag in flags):
await message.channel.send("You used a bad word!")
bad_webs = data['urls']
if "https://" in msg_content:
name = msg_content.split("https://www.")[1].split(".com")[0]
print(name)
for website in bad_webs.keys():
print(str(website))
if str(website).lower() in name.lower():
await message.reply(f'The url {message.author.name} has posted is for the site {website} which, according to AllSides.com has a bias of {bad_webs.get(website)}. View the linked media at your own discretion.')
# @client.event
# async def on_message_url(message):
# msg_content = message.content.lower()
# print(msg_content + "urls")
# path = "servers/" + str(message.guild.id) + ".json"
# data = json.load(open(path, 'r'))
# bad_webs = data['urls']
# #if link, check it, reply to message
# if "https://" in msg_content:
# name = msg_content.split("https://www.")[1].split(".com")[0]
# print(name)
# for website in bad_webs.keys():
# print(str(website))
# if str(website).lower() in name.lower():
# await message.reply(f'The url {message.author.name} has posted is for the site {website} which, according to AllSides.com has a bias of {bad_webs.get(website)}. View the linked media at your own discretion.')
client.run(TOKEN)