<commit_before>import logging
import random
from typing import List

import discord
from discord.ext import commands

from nabbot import NabBot
from .utils import CogUtils, checks, get_user_avatar, is_numeric
from .utils.context import NabCtx

log = logging.getLogger("nabbot")


class General(CogUtils):
    """General use commands."""
    def __init__(self, bot: NabBot):
        self.bot = bot

    # Commands
    @commands.command(aliases=["checkdm"])
    async def checkpm(self, ctx: NabCtx):
        """Checks if you can receive PMs from the bot.

        If you can't receive PMs, 'Allow direct messages from server members.' must be enabled in the Privacy Settings
         of any server where NabBot is in."""
        if ctx.guild is None:
            return await ctx.success("This is a private message, so yes... PMs are working.")
        try:
            await ctx.author.send("Testing PMs...")
            await ctx.success("You can receive PMs.")
        except discord.Forbidden:
            await ctx.error("You can't receive my PMs.\nTo enable, go to ")

    @commands.command(usage="<choices...>")
    async def choose(self, ctx, *choices: str):
        """Chooses between multiple choices.

        Each choice is separated by spaces. For choices that contain spaces surround it with quotes.
        e.g. "Choice A" ChoiceB "Choice C"
        """
        if not choices:
            await ctx.send(f"{ctx.tick(False)} I can't tell you what to choose if you don't give me choices")
            return
        user = ctx.author
        await ctx.send('Alright, **@{0}**, I choose: "{1}"'.format(user.display_name, random.choice(choices)))

    @commands.guild_only()
    @commands.has_permissions(manage_roles=True)
    @checks.can_embed()
    @commands.command(nam="permissions", aliases=["perms"])
    async def permissions(self, ctx: NabCtx, member: discord.Member = None, channel: discord.TextChannel = None):
        """Shows a member's permissions in the current channel.

        If no member is provided, it will show your permissions.
        Optionally, a channel can be provided as the second parameter, to check permissions in said channel."""
        member = member or ctx.author
        channel = channel or ctx.channel
        guild_permissions = channel.permissions_for(member)
        embed = discord.Embed(title=f"Permissions in #{channel.name}", colour=member.colour)
        embed.set_author(name=member.display_name, icon_url=get_user_avatar(member))
        allowed = []
        denied = []
        for name, value in guild_permissions:
            name = name.replace('_', ' ').replace('guild', 'server').title()
            if value:
                allowed.append(name)
            else:
                denied.append(name)
        if allowed:
            embed.add_field(name=f"{ctx.tick()}Allowed", value="\n".join(allowed))
        if denied:
            embed.add_field(name=f"{ctx.tick(False)}Denied", value="\n".join(denied))
        await ctx.send(embed=embed)

    @commands.guild_only()
    @checks.can_embed()
    @commands.command()
    async def quote(self, ctx: NabCtx, message_id: int):
        """Shows a messages by its ID.

        In order to get a message's id, you need to enable Developer Mode.
        Developer mode is found in `User Settings > Appearance`.
        Once enabled, you can right click a message and select **Copy ID**.

        Note that the bot won't attempt to search in channels you can't read."""
        channels: List[discord.TextChannel] = ctx.guild.text_channels
        message: discord.Message = None
        with ctx.typing():
            for channel in channels:
                bot_perm = ctx.bot_permissions
                auth_perm = ctx.author_permissions
                # Both bot and members must be able to read the channel.
                if not(bot_perm.read_message_history and bot_perm.read_messages and
                       auth_perm.read_message_history and auth_perm.read_messages):
                    continue
                try:
                    message = await channel.get_message(message_id)
                except discord.HTTPException:
                    continue
                if message is not None:
                    break
        if message is None:
            await ctx.send("I can't find that message, or it is in a channel you can't access.")
            return
        if not message.content and not message.attachments:
            await ctx.send("I can't quote embed messages.")
            return
        embed = discord.Embed(description=message.content, timestamp=message.created_at)
        try:
            embed.colour = message.author.colour
        except AttributeError:
            pass
        embed.set_author(name=message.author.display_name, icon_url=get_user_avatar(message.author),
                         url=message.jump_url)
        embed.set_footer(text=f"In #{message.channel.name}")
        if len(message.attachments) >= 1:
            attachment: discord.Attachment = message.attachments[0]<commit_msg>You can no longer quote messages from NSFW channels in regular channels<commit_after>import logging
import random
from typing import List

import discord
from discord.ext import commands

from nabbot import NabBot
from .utils import CogUtils, checks, get_user_avatar, is_numeric
from .utils.context import NabCtx

log = logging.getLogger("nabbot")


class General(CogUtils):
    """General use commands."""
    def __init__(self, bot: NabBot):
        self.bot = bot

    # Commands
    @commands.command(aliases=["checkdm"])
    async def checkpm(self, ctx: NabCtx):
        """Checks if you can receive PMs from the bot.

        If you can't receive PMs, 'Allow direct messages from server members.' must be enabled in the Privacy Settings
         of any server where NabBot is in."""
        if ctx.guild is None:
            return await ctx.success("This is a private message, so yes... PMs are working.")
        try:
            await ctx.author.send("Testing PMs...")
            await ctx.success("You can receive PMs.")
        except discord.Forbidden:
            await ctx.error("You can't receive my PMs.\nTo enable, go to ")

    @commands.command(usage="<choices...>")
    async def choose(self, ctx, *choices: str):
        """Chooses between multiple choices.

        Each choice is separated by spaces. For choices that contain spaces surround it with quotes.
        e.g. "Choice A" ChoiceB "Choice C"
        """
        if not choices:
            await ctx.send(f"{ctx.tick(False)} I can't tell you what to choose if you don't give me choices")
            return
        user = ctx.author
        await ctx.send('Alright, **@{0}**, I choose: "{1}"'.format(user.display_name, random.choice(choices)))

    @commands.guild_only()
    @commands.has_permissions(manage_roles=True)
    @checks.can_embed()
    @commands.command(nam="permissions", aliases=["perms"])
    async def permissions(self, ctx: NabCtx, member: discord.Member = None, channel: discord.TextChannel = None):
        """Shows a member's permissions in the current channel.

        If no member is provided, it will show your permissions.
        Optionally, a channel can be provided as the second parameter, to check permissions in said channel."""
        member = member or ctx.author
        channel = channel or ctx.channel
        guild_permissions = channel.permissions_for(member)
        embed = discord.Embed(title=f"Permissions in #{channel.name}", colour=member.colour)
        embed.set_author(name=member.display_name, icon_url=get_user_avatar(member))
        allowed = []
        denied = []
        for name, value in guild_permissions:
            name = name.replace('_', ' ').replace('guild', 'server').title()
            if value:
                allowed.append(name)
            else:
                denied.append(name)
        if allowed:
            embed.add_field(name=f"{ctx.tick()}Allowed", value="\n".join(allowed))
        if denied:
            embed.add_field(name=f"{ctx.tick(False)}Denied", value="\n".join(denied))
        await ctx.send(embed=embed)

    @commands.guild_only()
    @checks.can_embed()
    @commands.command()
    async def quote(self, ctx: NabCtx, message_id: int):
        """Shows a messages by its ID.

        In order to get a message's id, you need to enable Developer Mode.
        Developer mode is found in `User Settings > Appearance`.
        Once enabled, you can right click a message and select **Copy ID**.

        Note that the bot won't attempt to search in channels you can't read."""
        channels: List[discord.TextChannel] = ctx.guild.text_channels
        message: discord.Message = None
        with ctx.typing():
            for channel in channels:
                bot_perm = ctx.bot_permissions
                auth_perm = ctx.author_permissions
                # Both bot and members must be able to read the channel.
                if not(bot_perm.read_message_history and bot_perm.read_messages and
                       auth_perm.read_message_history and auth_perm.read_messages):
                    continue
                try:
                    message = await channel.get_message(message_id)
                except discord.HTTPException:
                    continue
                if message is not None:
                    break
        if message is None:
            await ctx.error("I can't find that message, or it is in a channel you can't access.")
            return
        if not message.content and not message.attachments:
            await ctx.error("I can't quote embed messages.")
            return
        if message.channel.nsfw and not ctx.channel.nsfw:
            await ctx.error("I can't quote messages from NSFW channels in SFW channels.")
            return
        embed = discord.Embed(description=message.content, timestamp=message.created_at)
        try:
            embed.colour = message.author.colour
        except AttributeError:
            pass
        embed.set_author(name=message.author.display_name, icon_url=get_user_avatar(message.author),
                         url=message.jump_url)
        embed.set_footer(text=f"In #{message.channel.name}")
        if len(message.attachments) >= 1:
            attachment: discord.Attachment = message.attachments[0]
{'fraction_non_alphanumeric': 0.09555062252678313, 'fraction_numerical': 0.0007721262426406717, 'mean_word_length': 2.3458185340652244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '569165', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2760, 'n_words': 899}