Permissions updates
This commit is contained in:
parent
cfa9642fb3
commit
9a3c86815d
8 changed files with 89 additions and 78 deletions
|
@ -7,6 +7,7 @@ from discord_slash.utils.manage_commands import create_option
|
||||||
|
|
||||||
from jarvis.db.types import Lock
|
from jarvis.db.types import Lock
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class LockCog(CacheCog):
|
class LockCog(CacheCog):
|
||||||
|
@ -65,7 +66,7 @@ class LockCog(CacheCog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_channels=True)
|
||||||
async def _lock(
|
async def _lock(
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
|
@ -111,7 +112,7 @@ class LockCog(CacheCog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_channels=True)
|
||||||
async def _unlock(
|
async def _unlock(
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
|
|
|
@ -9,6 +9,7 @@ from jarvis.config import get_config
|
||||||
from jarvis.db import DBManager
|
from jarvis.db import DBManager
|
||||||
from jarvis.db.types import Lock
|
from jarvis.db.types import Lock
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class LockdownCog(CacheCog):
|
class LockdownCog(CacheCog):
|
||||||
|
@ -35,7 +36,7 @@ class LockdownCog(CacheCog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_channels=True)
|
||||||
async def _lockdown_start(
|
async def _lockdown_start(
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
|
|
|
@ -11,6 +11,7 @@ from jarvis.db.types import MongoSort, Warning
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class WarningCog(CacheCog):
|
class WarningCog(CacheCog):
|
||||||
|
@ -41,7 +42,7 @@ class WarningCog(CacheCog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _warn(
|
async def _warn(
|
||||||
self, ctx: SlashContext, user: User, reason: str, duration: int = 24
|
self, ctx: SlashContext, user: User, reason: str, duration: int = 24
|
||||||
):
|
):
|
||||||
|
@ -99,7 +100,7 @@ class WarningCog(CacheCog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _warnings(self, ctx: SlashContext, user: User, active: bool = 1):
|
async def _warnings(self, ctx: SlashContext, user: User, active: bool = 1):
|
||||||
active = bool(active)
|
active = bool(active)
|
||||||
exists = self.check_cache(ctx, user_id=user.id, active=active)
|
exists = self.check_cache(ctx, user_id=user.id, active=active)
|
||||||
|
@ -132,7 +133,7 @@ class WarningCog(CacheCog):
|
||||||
else:
|
else:
|
||||||
fields = []
|
fields = []
|
||||||
for warn in active_warns:
|
for warn in active_warns:
|
||||||
admin = ctx.guild.get(warn.admin)
|
admin = ctx.guild.get_member(warn.admin)
|
||||||
admin_name = "||`[redacted]`||"
|
admin_name = "||`[redacted]`||"
|
||||||
if admin:
|
if admin:
|
||||||
admin_name = f"{admin.name}#{admin.discriminator}"
|
admin_name = f"{admin.name}#{admin.discriminator}"
|
||||||
|
|
|
@ -8,6 +8,7 @@ from discord_slash.utils.manage_commands import create_option
|
||||||
|
|
||||||
from jarvis.data.unicode import emoji_list
|
from jarvis.data.unicode import emoji_list
|
||||||
from jarvis.db.types import Autoreact
|
from jarvis.db.types import Autoreact
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class AutoReactCog(commands.Cog):
|
class AutoReactCog(commands.Cog):
|
||||||
|
@ -28,7 +29,7 @@ class AutoReactCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _autoreact_create(self, ctx: SlashContext, channel: TextChannel):
|
async def _autoreact_create(self, ctx: SlashContext, channel: TextChannel):
|
||||||
if not isinstance(channel, TextChannel):
|
if not isinstance(channel, TextChannel):
|
||||||
await ctx.send("Channel must be a text channel", hidden=True)
|
await ctx.send("Channel must be a text channel", hidden=True)
|
||||||
|
@ -62,6 +63,7 @@ class AutoReactCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _autoreact_delete(self, ctx, channel: TextChannel):
|
async def _autoreact_delete(self, ctx, channel: TextChannel):
|
||||||
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id).delete()
|
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id).delete()
|
||||||
if exists:
|
if exists:
|
||||||
|
@ -90,7 +92,7 @@ class AutoReactCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _autoreact_add(self, ctx, channel: TextChannel, emote: str):
|
async def _autoreact_add(self, ctx, channel: TextChannel, emote: str):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
custom_emoji = self.custom_emote.match(emote)
|
custom_emoji = self.custom_emote.match(emote)
|
||||||
|
@ -152,7 +154,7 @@ class AutoReactCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _autoreact_remove(self, ctx, channel: TextChannel, emote: str):
|
async def _autoreact_remove(self, ctx, channel: TextChannel, emote: str):
|
||||||
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id)
|
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id)
|
||||||
if not exists:
|
if not exists:
|
||||||
|
@ -185,7 +187,7 @@ class AutoReactCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _autoreact_list(self, ctx, channel: TextChannel):
|
async def _autoreact_list(self, ctx, channel: TextChannel):
|
||||||
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id)
|
exists = Autoreact.get(guild=ctx.guild.id, channel=channel.id)
|
||||||
if not exists:
|
if not exists:
|
||||||
|
|
|
@ -368,6 +368,7 @@ class GitlabCog(CacheCog):
|
||||||
|
|
||||||
self.cache[hash(paginator)] = {
|
self.cache[hash(paginator)] = {
|
||||||
"user": ctx.author.id,
|
"user": ctx.author.id,
|
||||||
|
"guild": ctx.guild.id,
|
||||||
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
"command": ctx.subcommand_name,
|
"command": ctx.subcommand_name,
|
||||||
"state": state,
|
"state": state,
|
||||||
|
@ -459,6 +460,7 @@ class GitlabCog(CacheCog):
|
||||||
|
|
||||||
self.cache[hash(paginator)] = {
|
self.cache[hash(paginator)] = {
|
||||||
"user": ctx.author.id,
|
"user": ctx.author.id,
|
||||||
|
"guild": ctx.guild.id,
|
||||||
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
"command": ctx.subcommand_name,
|
"command": ctx.subcommand_name,
|
||||||
"state": state,
|
"state": state,
|
||||||
|
@ -528,6 +530,7 @@ class GitlabCog(CacheCog):
|
||||||
|
|
||||||
self.cache[hash(paginator)] = {
|
self.cache[hash(paginator)] = {
|
||||||
"user": ctx.author.id,
|
"user": ctx.author.id,
|
||||||
|
"guild": ctx.guild.id,
|
||||||
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
"timeout": datetime.utcnow() + timedelta(minutes=5),
|
||||||
"command": ctx.subcommand_name,
|
"command": ctx.subcommand_name,
|
||||||
"paginator": paginator,
|
"paginator": paginator,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from discord_slash.utils.manage_commands import create_option
|
||||||
from jarvis.db.types import Setting
|
from jarvis.db.types import Setting
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class RolegiverCog(commands.Cog):
|
class RolegiverCog(commands.Cog):
|
||||||
|
@ -25,7 +26,7 @@ class RolegiverCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _rolegiver_add(self, ctx: SlashContext, role: Role):
|
async def _rolegiver_add(self, ctx: SlashContext, role: Role):
|
||||||
setting = Setting.get(guild=ctx.guild.id, setting="rolegiver")
|
setting = Setting.get(guild=ctx.guild.id, setting="rolegiver")
|
||||||
if setting and role.id in setting.value:
|
if setting and role.id in setting.value:
|
||||||
|
@ -82,7 +83,7 @@ class RolegiverCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _rolegiver_remove(self, ctx: SlashContext, role: Role):
|
async def _rolegiver_remove(self, ctx: SlashContext, role: Role):
|
||||||
setting = Setting.get(guild=ctx.guild.id, setting="rolegiver")
|
setting = Setting.get(guild=ctx.guild.id, setting="rolegiver")
|
||||||
if not setting or (setting and not setting.value):
|
if not setting or (setting and not setting.value):
|
||||||
|
|
|
@ -30,7 +30,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@admin_or_permissions(mute_members=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _mute(self, ctx, role: Role):
|
async def _mute(self, ctx, role: Role):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
self.update_settings("mute", role.id, ctx.guild.id)
|
self.update_settings("mute", role.id, ctx.guild.id)
|
||||||
|
@ -49,7 +49,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _modlog(self, ctx, channel: TextChannel):
|
async def _modlog(self, ctx, channel: TextChannel):
|
||||||
if not isinstance(channel, TextChannel):
|
if not isinstance(channel, TextChannel):
|
||||||
await ctx.send("Channel must be a TextChannel", hidden=True)
|
await ctx.send("Channel must be a TextChannel", hidden=True)
|
||||||
|
@ -72,7 +72,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _userlog(self, ctx, channel: TextChannel):
|
async def _userlog(self, ctx, channel: TextChannel):
|
||||||
if not isinstance(channel, TextChannel):
|
if not isinstance(channel, TextChannel):
|
||||||
await ctx.send("Channel must be a TextChannel", hidden=True)
|
await ctx.send("Channel must be a TextChannel", hidden=True)
|
||||||
|
@ -95,7 +95,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _massmention(self, ctx, amount: int):
|
async def _massmention(self, ctx, amount: int):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
self.update_settings("massmention", amount, ctx.guild.id)
|
self.update_settings("massmention", amount, ctx.guild.id)
|
||||||
|
@ -114,7 +114,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@admin_or_permissions(kick_members=True, ban_members=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _verified(self, ctx, role: Role):
|
async def _verified(self, ctx, role: Role):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
self.update_settings("verified", role.id, ctx.guild.id)
|
self.update_settings("verified", role.id, ctx.guild.id)
|
||||||
|
@ -133,7 +133,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@admin_or_permissions(kick_members=True, ban_members=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _unverified(self, ctx, role: Role):
|
async def _unverified(self, ctx, role: Role):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
self.update_settings("unverified", role.id, ctx.guild.id)
|
self.update_settings("unverified", role.id, ctx.guild.id)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from discord_slash.utils.manage_commands import create_option
|
||||||
|
|
||||||
from jarvis.db.types import Star, Starboard
|
from jarvis.db.types import Star, Starboard
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
supported_images = [
|
supported_images = [
|
||||||
"image/png",
|
"image/png",
|
||||||
|
@ -24,7 +25,7 @@ class StarboardCog(commands.Cog):
|
||||||
name="list",
|
name="list",
|
||||||
description="Lists all Starboards",
|
description="Lists all Starboards",
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _list(self, ctx):
|
async def _list(self, ctx):
|
||||||
starboards = Starboard.get_many(guild=ctx.guild.id)
|
starboards = Starboard.get_many(guild=ctx.guild.id)
|
||||||
if starboards != []:
|
if starboards != []:
|
||||||
|
@ -48,7 +49,7 @@ class StarboardCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _create(self, ctx, channel: TextChannel):
|
async def _create(self, ctx, channel: TextChannel):
|
||||||
if channel not in ctx.guild.channels:
|
if channel not in ctx.guild.channels:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -88,7 +89,7 @@ class StarboardCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _delete(self, ctx, channel: TextChannel):
|
async def _delete(self, ctx, channel: TextChannel):
|
||||||
deleted = Starboard.get(
|
deleted = Starboard.get(
|
||||||
channel=channel.id, guild=ctx.guild.id
|
channel=channel.id, guild=ctx.guild.id
|
||||||
|
@ -129,7 +130,7 @@ class StarboardCog(commands.Cog):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@admin_or_permissions(manage_server=True)
|
||||||
async def _star_add(
|
async def _star_add(
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
|
@ -216,66 +217,67 @@ class StarboardCog(commands.Cog):
|
||||||
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
|
"Message saved to Starboard.\n" + f"See it in {starboard.mention}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@cog_ext.cog_subcommand(
|
||||||
base="star",
|
base="star",
|
||||||
name="delete",
|
name="delete",
|
||||||
description="Delete a starred message",
|
description="Delete a starred message",
|
||||||
guild_ids=[
|
guild_ids=[
|
||||||
862402786116763668,
|
862402786116763668,
|
||||||
418094694325813248,
|
418094694325813248,
|
||||||
578757004059738142,
|
578757004059738142,
|
||||||
],
|
],
|
||||||
options=[
|
options=[
|
||||||
create_option(
|
create_option(
|
||||||
name="id",
|
name="id",
|
||||||
description="Star to delete",
|
description="Star to delete",
|
||||||
option_type=4,
|
option_type=4,
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
create_option(
|
create_option(
|
||||||
name="starboard",
|
name="starboard",
|
||||||
description="Starboard to delete star from",
|
description="Starboard to delete star from",
|
||||||
option_type=7,
|
option_type=7,
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def _star_get(
|
@admin_or_permissions(manage_server=True)
|
||||||
self,
|
async def _star_delete(
|
||||||
ctx: SlashContext,
|
self,
|
||||||
id: int,
|
ctx: SlashContext,
|
||||||
starboard: TextChannel,
|
id: int,
|
||||||
):
|
starboard: TextChannel,
|
||||||
if not isinstance(starboard, TextChannel):
|
):
|
||||||
await ctx.send("Channel must be a TextChannel", hidden=True)
|
if not isinstance(starboard, TextChannel):
|
||||||
return
|
await ctx.send("Channel must be a TextChannel", hidden=True)
|
||||||
exists = Starboard.get(channel=starboard.id, guild=ctx.guild.id)
|
return
|
||||||
if not exists:
|
exists = Starboard.get(channel=starboard.id, guild=ctx.guild.id)
|
||||||
await ctx.send(
|
if not exists:
|
||||||
f"Starboard does not exist in {starboard.mention}. "
|
await ctx.send(
|
||||||
+ "Please create it first",
|
f"Starboard does not exist in {starboard.mention}. "
|
||||||
hidden=True,
|
+ "Please create it first",
|
||||||
)
|
hidden=True,
|
||||||
return
|
|
||||||
|
|
||||||
star = Star.get(
|
|
||||||
starboard=starboard.id,
|
|
||||||
id=id,
|
|
||||||
guild=ctx.guild.id,
|
|
||||||
active=True,
|
|
||||||
)
|
)
|
||||||
if not star:
|
return
|
||||||
await ctx.send(f"No star exists with id {id}", hidden=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
message = await starboard.fetch_message(star.star)
|
star = Star.get(
|
||||||
if message:
|
starboard=starboard.id,
|
||||||
await message.delete()
|
id=id,
|
||||||
|
guild=ctx.guild.id,
|
||||||
|
active=True,
|
||||||
|
)
|
||||||
|
if not star:
|
||||||
|
await ctx.send(f"No star exists with id {id}", hidden=True)
|
||||||
|
return
|
||||||
|
|
||||||
star.active = False
|
message = await starboard.fetch_message(star.star)
|
||||||
star.update()
|
if message:
|
||||||
|
await message.delete()
|
||||||
|
|
||||||
await ctx.send(f"Star {id} deleted")
|
star.active = False
|
||||||
|
star.update()
|
||||||
|
|
||||||
|
await ctx.send(f"Star {id} deleted")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
Loading…
Add table
Reference in a new issue