-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkick-unverified.py
73 lines (63 loc) · 3.29 KB
/
kick-unverified.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
import discord
import pytz
import logging
from datetime import datetime, timedelta
import os
TOKEN = os.environ['DISCORD_BOT_TOKEN']
GUILD_NAME = os.environ['DISCORD_GUILD_NAME']
GUILD_ID = os.environ['DISCORD_GUILD_ID']
KICK_TIME_THRESHOLD = timedelta(minutes=15)
BAN_LIST = ["ZetaChain |", "MEE6"]
logging.basicConfig(level=logging.INFO)
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
current_time = datetime.now(pytz.utc)
ban_count = 0
kick_count = 0
for guild in client.guilds:
if guild.name == GUILD_NAME or guild.id == GUILD_ID:
logging.debug(
f'{client.user} is running in the following server:\n{guild.name} (id: {guild.id})')
# Iterate over each member and kick bots who can't verify
for member in guild.members:
try:
# Find members with a single role (@everyone only and no other role)
if len(member.roles) == 1:
logging.debug(
f"Member {member.name} (id: {member.id}) has no roles. Checking join time...")
# If this member has been in the server for more than {KICK_TIME_THRESHOLD} minutes
# and still has no roles, kick them
join_time = member.joined_at
time_since_join = current_time - join_time
if time_since_join > KICK_TIME_THRESHOLD:
try:
logging.debug(
f"Member {member.name} (id: {member.id}) has been in the server for more than {KICK_TIME_THRESHOLD} without obtaining a role...")
# If their name matches known bots ban them for good measure
if any(ban_name.lower() in member.name.lower() for ban_name in BAN_LIST):
logging.info(
f"Banning Member {member.name} (id: {member.id}) for matching known bot name")
await member.ban(reason="Name matches name used by bot attacks")
ban_count += 1
# If it's not a known bot,just kick them in case it's a real user
else:
logging.info(
f"Kicking Member {member.name} (id: {member.id})")
await member.kick()
kick_count += 1
except Exception as e:
logging.error(
f"An error occurred while kicking member {member.name} (id: {member.id}): {e}")
continue
except Exception as e:
logging.error(
f"An error occurred while processing member {member.name} (id: {member.id}): {e}")
continue
logging.info("--------------------")
logging.info(f"Kicked {kick_count} members")
logging.info(f"Banned {ban_count} members")
break
await client.close()
client.run(TOKEN)