-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
123 lines (100 loc) · 3.45 KB
/
bot.py
File metadata and controls
123 lines (100 loc) · 3.45 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import discord
import requests
import json
from discord.ext import commands
from discord.utils import get
# Constants
TOKEN = 'ODA1MTg4Njk4MjUzNjg4ODQz.YBXQaQ.vSqL3djzDqWVTDyDnzeNPUeyOs4'
ADMIN_ROLE_NAME = 'admin'
JOIN_CHANNEL_ID = '805189024200785964'
GET_USER = 'http://localhost:5000/api/bot/user/'
LEAVE_USER = 'http://localhost:5000/api/bot/leave/'
# Client
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="$ ", intents=intents)
@client.event
async def on_ready():
print("We have logged in as {0.user}".format(client))
@client.event
async def on_member_join(member):
await client.wait_until_ready()
guild = member.guild
discord_id = member.id
r = requests.get(GET_USER+str(discord_id))
data = r.text
if r.status_code == 404:
await member.kick()
return
user_info = json.loads(data)
partner_id = user_info[0]['partnerID']
if partner_id:
print(partner_id)
partner = guild.get_member(int(partner_id))
print(partner)
if partner is not None:
roles = partner.roles
for role in roles:
if role.name == 'Viber':
await member.add_roles(role)
return
else:
await member.kick()
return
viber = await guild.create_role(name=f'Viber', mentionable=True)
permissions = {
guild.default_role: discord.PermissionOverwrite(view_channel=False),
viber: discord.PermissionOverwrite(view_channel=True)
}
category = await guild.create_category(f"Vibe",overwrites=permissions)
text = await category.create_text_channel("text")
voice = await category.create_voice_channel("Voice")
await text.edit(permissions_synced = True)
await voice.edit(permissions_synced = True)
category.position = 100
await member.add_roles(viber)
await text.send("Welcome!")
# Send GET_USER request
@client.command(name='hello()')
async def _hello(ctx):
await ctx.channel.send("\> Hello!")
# Kick user and delete category + channels
@client.command(name='done()')
async def _done(ctx):
guild = ctx.guild
category = ctx.channel.category
user = ctx.message.author
r = requests.get(GET_USER+str(discord_id))
data = r.text
user_info = json.loads(data)
partner_id = user_info[0]['partnerID']
partner = guild.get_member(int(partner_id))
await guild.kick(partner)
await user.kick()
r = requests.post(LEAVE_USER+str(user.id))
await ctx.send(f"**{user}** has been kicked for **no reason**.")
for channel in category.channels:
if channel:
await channel.delete()
await category.delete()
@client.command(name='cleanup()')
async def _cleanup(ctx):
guild = ctx.guild
if isAdmin(ctx, ADMIN_ROLE_NAME):
roles = guild.roles
categories = guild.categories
for role in roles:
if "Viber" in role.name:
await role.delete()
for category in categories:
if "Vibe" in category.name:
for channel in category.channels:
if channel:
await channel.delete()
await category.delete()
await ctx.send("\> Done!")
else:
await ctx.channel.send("\> You are not authorized to use that command!")
def isAdmin(message, roleName):
return roleName.lower() in [role.name.lower() for role in message.author.roles]
client.run(TOKEN)