<commit_before>import datetime
import json
import re
from datetime import date, timedelta
from random import choice
from textwrap import dedent, indent

import requests
from discord import Embed

from musicbot.constants import VERSION as BOTVERSION
from musicbot.tungsten import Tungsten
from musicbot.utils import (Response, block_user, command_info,
                            get_dev_version, get_version_changelog, hex_to_dec,
                            owner_only, prettydate)


class InfoCommands:

    @command_info("1.9.5", 1477774380, {
        "3.4.5": (1497616203, "Improved default help message using embeds"),
        "3.6.0": (1497904733, "Fixed weird indent of some help texts"),
        "3.7.0": (1498233256, "Some better help texts"),
        "3.7.1": (1498237739, "Added interactive help"),
        "3.7.4": (1498318916, "Added \"lyrics\" function help text"),
        "4.2.2": (1500905513, "Updated help texts"),
        "4.6.0": (1502208273, "Added a missing comma so resume and volume don't show on the same line"),
        "4.7.2": (1503855125, "Updated command list")
    })
    async def cmd_help(self, channel, leftover_args):
        """
        ///|Usage
        `{command_prefix}help [command]`
        ///|Explanation
        Logs a help message.
        ///|Interactive
        `{command_prefix}help <query>`
        """
        command = None

        if len(leftover_args) > 0:
            command = " ".join(leftover_args)

        if command:
            cmd = getattr(self, "cmd_" + command, None)
            if cmd:
                documentation = cmd.__doc__.format(
                    command_prefix=self.config.command_prefix)
                em = Embed(title="**{}**".format(command.upper()))
                fields = documentation.split("///")
                if len(fields) < 2:  # backward compatibility
                    return Response(
                        "```\n{}```".format(dedent(cmd.__doc__).format(command_prefix=self.config.command_prefix)))

                for field in fields:
                    if field is None or field is "":
                        continue
                    inline = True
                    if field.startswith("(NL)"):
                        inline = False
                        field = field[4:]
                        # print(field)

                    match = re.match(r"\|(.+)\n((?:.|\n)+)", field)
                    if match is None:
                        continue
                    title, text = match.group(1, 2)

                    em.add_field(
                        name="**{}**".format(title), value=dedent(text), inline=inline)
                await self.send_message(channel, embed=em)
                return
            else:
                await self.send_typing(channel)
                params = {
                    "v": date.today().strftime("%d/%m/%y"),
                    "q": command}
                headers = {
                    "Authorization": "Bearer CU4UAUCKWN37QLXHMBOYZ425NOGBMIYK"}
                resp = requests.get("https://api.wit.ai/message",
                                    params=params, headers=headers)
                data = resp.json()
                entities = data["entities"]

                return Response("**This is still a work-in-progress**\n{}".format(json.dumps(entities, indent=4)))

        else:
            em = Embed(
                title="GIESELA HELP",
                url="http://siku2.github.io/Giesela/",
                colour=hex_to_dec("#828c51"),
                description="Here are some of the most useful commands,\nYou can always use `{0}help <cmd>` to get more detailed information on a command".
                format(self.config.command_prefix)
            )

            music_commands = "\n".join([
                "`{0}play` play music",
                "`{0}search` search for music",
                "`{0}radio` listen to the best radio stations",
                "`{0}stream` enqueue a livestream",
                "`{0}spotfy` spotify integration",
                "`{0}pause` pause playback",
                "`{0}resume` resume playback",
                "`{0}volume` change volume",
                "`{0}seek` seek to a timestamp",
                "`{0}fwd` forward time",
                "`{0}rwd` rewind time"
            ]).format(self.config.command_prefix)
            em.add_field(name="Music", value=music_commands, inline=False)

            queue_commands = "\n".join([
                "`{0}queue` show the queue",
                "`{0}history` show playback history",
                "`{0}np` more information on the current entry",
                "`{0}skip` skip to the next entry in queue",
                "`{0}replay` replay the current entry",
                "`{0}repeat` change repeat mode",
                "`{0}remove` remove entry from queue",
                "`{0}clear` remove all entries from queue",
                "`{0}shuffle` shuffle the queue",
                "`{0}promote` promote entry to front",
                "`{0}autoplay` when you're out of ideas just let Giesela choose"
            ]).format(self.config.command_prefix)
            em.add_field(name="Queue", value=queue_commands, inline=False)

            playlist_commands = "\n".join([<commit_msg>spelling Spotify correctly xD + random colors on help menu <commit_after>import datetime
import json
import re
import random
from datetime import date, timedelta
from random import choice
from textwrap import dedent, indent

import requests
from discord import Embed

from musicbot.constants import VERSION as BOTVERSION
from musicbot.tungsten import Tungsten
from musicbot.utils import (Response, block_user, command_info,
                            get_dev_version, get_version_changelog, hex_to_dec,
                            owner_only, prettydate)


class InfoCommands:

    @command_info("1.9.5", 1477774380, {
        "3.4.5": (1497616203, "Improved default help message using embeds"),
        "3.6.0": (1497904733, "Fixed weird indent of some help texts"),
        "3.7.0": (1498233256, "Some better help texts"),
        "3.7.1": (1498237739, "Added interactive help"),
        "3.7.4": (1498318916, "Added \"lyrics\" function help text"),
        "4.2.2": (1500905513, "Updated help texts"),
        "4.6.0": (1502208273, "Added a missing comma so resume and volume don't show on the same line"),
        "4.7.2": (1503855125, "Updated command list")
    })
    async def cmd_help(self, channel, leftover_args):
        """
        ///|Usage
        `{command_prefix}help [command]`
        ///|Explanation
        Logs a help message.
        ///|Interactive
        `{command_prefix}help <query>`
        """
        command = None

        if len(leftover_args) > 0:
            command = " ".join(leftover_args)

        if command:
            cmd = getattr(self, "cmd_" + command, None)
            if cmd:
                documentation = cmd.__doc__.format(
                    command_prefix=self.config.command_prefix)
                em = Embed(title="**{}**".format(command.upper()))
                fields = documentation.split("///")
                if len(fields) < 2:  # backward compatibility
                    return Response(
                        "```\n{}```".format(dedent(cmd.__doc__).format(command_prefix=self.config.command_prefix)))

                for field in fields:
                    if field is None or field is "":
                        continue
                    inline = True
                    if field.startswith("(NL)"):
                        inline = False
                        field = field[4:]
                        # print(field)

                    match = re.match(r"\|(.+)\n((?:.|\n)+)", field)
                    if match is None:
                        continue
                    title, text = match.group(1, 2)

                    em.add_field(
                        name="**{}**".format(title), value=dedent(text), inline=inline)
                await self.send_message(channel, embed=em)
                return
            else:
                await self.send_typing(channel)
                params = {
                    "v": date.today().strftime("%d/%m/%y"),
                    "q": command}
                headers = {
                    "Authorization": "Bearer <KEY>"}
                resp = requests.get("https://api.wit.ai/message",
                                    params=params, headers=headers)
                data = resp.json()
                entities = data["entities"]

                return Response("**This is still a work-in-progress**\n{}".format(json.dumps(entities, indent=4)))

        else:
            em = Embed(
                title="GIESELA HELP",
                url="http://siku2.github.io/Giesela/",
                colour=hex_to_dec("#%06x" % random.randint(0, 0xFFFFFF)),
                description="Here are some of the most useful commands,\nYou can always use `{0}help <cmd>` to get more detailed information on a command".
                format(self.config.command_prefix)
            )

            music_commands = "\n".join([
                "`{0}play` play music",
                "`{0}search` search for music",
                "`{0}radio` listen to the best radio stations",
                "`{0}stream` enqueue a livestream",
                "`{0}spotify` spotify integration",
                "`{0}pause` pause playback",
                "`{0}resume` resume playback",
                "`{0}volume` change volume",
                "`{0}seek` seek to a timestamp",
                "`{0}fwd` forward time",
                "`{0}rwd` rewind time"
            ]).format(self.config.command_prefix)
            em.add_field(name="Music", value=music_commands, inline=False)

            queue_commands = "\n".join([
                "`{0}queue` show the queue",
                "`{0}history` show playback history",
                "`{0}np` more information on the current entry",
                "`{0}skip` skip to the next entry in queue",
                "`{0}replay` replay the current entry",
                "`{0}repeat` change repeat mode",
                "`{0}remove` remove entry from queue",
                "`{0}clear` remove all entries from queue",
                "`{0}shuffle` shuffle the queue",
                "`{0}promote` promote entry to front",
                "`{0}autoplay` when you're out of ideas just let Giesela choose"
            ]).format(self.config.command_prefix)
            em.add_field(name="Queue", value=queue_commands, inline=False)

            playlist_commands = "\n".join([
{'fraction_non_alphanumeric': 0.12328638497652582, 'fraction_numerical': 0.029014084507042254, 'mean_word_length': 1.6409620629804116, 'pattern_counts': {'":': 24, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7371897', 'n_tokens_mistral': 3180, 'n_tokens_neox': 2823, 'n_words': 758}