-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.py
executable file
·84 lines (73 loc) · 2.85 KB
/
checks.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
import discord
from discord.ext import commands
def is_staff_check():
"""Check if user is staff in the server"""
def predicate(ctx):
return is_staff(ctx.bot, ctx.guild, ctx.author)
return commands.check(predicate)
def is_staff(client, guild, member):
db = client.variables.get(guild.id)
role = db['min_staff_role']
return member.top_role >= role or member.id == 196282885601361920
def is_bots_channel():
"Check if command is run in bots channel"
def predicate(ctx):
db = ctx.bot.variables.get(ctx.guild.id)
channel = db['bots_channel']
return ctx.channel and ctx.channel == channel
return commands.check(predicate)
def is_role_or_higher(member, role):
"""Base check for if user has a role or higher"""
if member:
if member.top_role:
return member.top_role >= role
return False
return False
def has_manage_roles():
def predicate(ctx):
return ctx.author.guild_permissions.manage_roles
return commands.check(predicate)
def in_voice_channel():
"""Check if user is in a voice channel"""
def predicate(ctx):
if ctx.author.voice is None:
return False
return True
return commands.check(predicate)
def is_dj():
"""Check if user has a role named 'DJ'"""
def predicate(ctx):
if ctx.message.author.guild_permissions.administrator:
return True
role = discord.utils.get(ctx.guild.roles, name="DJ")
if role in ctx.author.roles:
return True
#await ctx.say("The 'DJ' Role is required to use this command.", delete_after=4)
return False
return commands.check(predicate)
# async def audio_playing(ctx):
# """Checks that audio is currently playing before continuing."""
# client = ctx.guild.voice_client
# if client and client.channel and client.source:
# return True
# else:
# raise commands.CommandError("Not currently playing any audio.")
#
# async def in_same_voice_channel(ctx):
# """Checks that the command sender is in the same voice channel as the bot."""
# voice = ctx.author.voice
# bot_voice = ctx.guild.voice_client
# if voice and bot_voice and voice.channel and bot_voice.channel and voice.channel == bot_voice.channel:
# return True
# else:
# raise commands.CommandError("You need to be in the same voice channel as the bot to use this command.")
#
# async def is_audio_requester(ctx):
# """Checks that the command sender is the song requester."""
# music = ctx.bot.get_cog("Music")
# state = music.get_state(ctx.guild)
# permissions = ctx.channel.permissions_for(ctx.author)
# if permissions.administrator or state.is_requester(ctx.author):
# return True
# else:
# raise commands.CommandError("You need to be the song requester or an admin to use this command.")