-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
71 lines (57 loc) · 2.16 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
70
71
"""
Nejo - A protection bot for Discord.
Copyright (C) 2024 ItsAsheer, NejoBot developers and external contributers.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nextcord
import requests
import logging
import json
logging.basicConfig(level=logging.INFO)
intents = nextcord.Intents.default()
intents.members = True
client = nextcord.Client(intents=intents)
BLACKLIST_URL = "https://kickthespy.pet/ids"
def get_blacklisted_ids():
try:
response = requests.get(BLACKLIST_URL)
response.raise_for_status()
ids = response.text.splitlines()
return set(ids)
except requests.RequestException as e:
logging.error(f"Error fetching blacklist: {e}")
return set()
blacklisted_ids = get_blacklisted_ids()
@client.event
async def on_ready():
logging.info(f'Bot connected as {client.user}')
@client.event
async def on_member_join(member):
if str(member.id) in blacklisted_ids:
try:
await member.send("You are blacklisted, as you probably are spy.pet. Contact Nejo Developers for more information.")
except nextcord.Forbidden:
logging.warning(f"Could not send DM to {member.name}")
await member.kick(reason="User is blacklisted")
def load_token():
try:
with open('env.json') as f:
data = json.load(f)
return data['token']
except (FileNotFoundError, KeyError, json.JSONDecodeError) as e:
logging.error(f"Error loading token: {e}")
return None
token = load_token()
if token:
client.run(token)
else:
logging.error("Bot token not found. Exiting.")