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

from discord.ext import commands 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(): def is_nsfw():

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

def predicate(ctx): def predicate(ctx):
gs = roxbot.guild_settings.get(ctx.guild) gs = roxbot.guild_settings.get(ctx.guild)
if gs["voice"]["need_perms"]: 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: else:
return True return True


self.playlist[ctx.guild.id].append(video) self.playlist[ctx.guild.id].append(video)
return 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.guild_only()
@commands.command() @commands.command()
async def join(self, ctx, *, channel: discord.VoiceChannel = None): async def join(self, ctx, *, channel: discord.VoiceChannel = None):
voice = roxbot.guild_settings.get(guild)["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. # 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: if not ctx.author.voice:
raise commands.CommandError("You're not in the same voice channel as Roxbot.") raise commands.CommandError("You're not in the same voice channel as Roxbot.")
if ctx.author.voice.channel != ctx.voice_client.channel: if ctx.author.voice.channel != ctx.voice_client.channel:
video = video["entries"][0] video = video["entries"][0]


# Duration limiter handling # 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.") raise commands.CommandError("Cannot play video, duration is bigger than the max duration allowed.")


# Actual playing stuff section. # Actual playing stuff section.

+ 23
- 2
roxbot/utils.py View File



import random import random
import asyncio import asyncio
import discord
import argparse 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 import guild_settings
from roxbot.enums import EmbedColours from roxbot.enums import EmbedColours


if not url: if not url:
url = endpoint_url + "{0[directory]}/{0[image]}".format(post) url = endpoint_url + "{0[directory]}/{0[image]}".format(post)
return url 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