Browse Source

added more util funcs and fixed bug by using wrappers instead of proper functions :face_palm:

tags/v2.1.0
Roxie Gibson 5 years ago
parent
commit
c99231b185
3 changed files with 31 additions and 12 deletions
  1. +4
    -6
      roxbot/checks.py
  2. +4
    -4
      roxbot/cogs/voice.py
  3. +23
    -2
      roxbot/utils.py

+ 4
- 6
roxbot/checks.py View File

@@ -29,12 +29,10 @@ import discord
from discord.ext import commands


def has_permission_or_owner(**perms):
def predicate(ctx):
if ctx.author.id == roxbot.owner:
return True
return commands.has_permissions(**perms)
return commands.check(predicate)
def has_permissions_or_owner(**perms):
def pred(ctx):
return roxbot.utils.has_permissions_or_owner(ctx, **perms)
return commands.check(pred)


def is_nsfw():

+ 4
- 4
roxbot/cogs/voice.py View File

@@ -62,7 +62,7 @@ def need_perms():
def predicate(ctx):
gs = roxbot.guild_settings.get(ctx.guild)
if gs["voice"]["need_perms"]:
return roxbot.checks.has_permission_or_owner(manage_channels=True)
return roxbot.utils.has_permissions_or_owner(ctx, manage_channels=True)
else:
return True

@@ -231,7 +231,7 @@ class Voice:
self.playlist[ctx.guild.id].append(video)
return video

@roxbot.checks.has_permission_or_owner(manage_channels=True)
@roxbot.checks.has_permissions_or_owner(manage_channels=True)
@commands.guild_only()
@commands.command()
async def join(self, ctx, *, channel: discord.VoiceChannel = None):
@@ -293,7 +293,7 @@ class Voice:
voice = roxbot.guild_settings.get(guild)["voice"]

# Checks if invoker is in voice with the bot. Skips admins and mods and owner and if the song was queued previously.
if not (roxbot.checks.has_permission_or_owner(manage_channels=True) or from_queue):
if not (roxbot.utils.has_permissions_or_owner(ctx, manage_channels=True) or from_queue):
if not ctx.author.voice:
raise commands.CommandError("You're not in the same voice channel as Roxbot.")
if ctx.author.voice.channel != ctx.voice_client.channel:
@@ -318,7 +318,7 @@ class Voice:
video = video["entries"][0]

# Duration limiter handling
if video.get("duration", 1) > voice["max_length"] and not roxbot.checks.has_permission_or_owner(manage_channels=True):
if video.get("duration", 1) > voice["max_length"] and not roxbot.utils.has_permissions_or_owner(ctx, manage_channels=True):
raise commands.CommandError("Cannot play video, duration is bigger than the max duration allowed.")

# Actual playing stuff section.

+ 23
- 2
roxbot/utils.py View File

@@ -25,10 +25,12 @@

import random
import asyncio
import discord
import argparse

from roxbot import http
import discord
from discord.ext import commands

from roxbot import http, config
from roxbot import guild_settings
from roxbot.enums import EmbedColours

@@ -226,3 +228,22 @@ async def danbooru_clone_api_req(channel, base_url, endpoint_url, cache=None, ta
if not url:
url = endpoint_url + "{0[directory]}/{0[image]}".format(post)
return url


def has_permissions(ctx, **perms):
"""Copy of code from discord.py to work outside of wrappers"""
ch = ctx.channel
permissions = ch.permissions_for(ctx.author)

missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value]

if not missing:
return True

raise commands.MissingPermissions(missing)


def has_permissions_or_owner(ctx, **perms):
if ctx.author.id == config.config["Roxbot"]["OwnerID"]:
return True
return has_permissions(ctx, **perms)

Loading…
Cancel
Save