<commit_before><?php

namespace Bot\Commands;

use Bot\Bot;
use Discord\Discord;
use Discord\Parts\Channel\Message;

abstract class BaseCommand
{
    /**
     * Keywords that will trigger the command
     *
     * @var string|array
     */
    public $keywords = [];

    /**
     * Determine if only admins can use the command
     *
     * @var bool
     */
    public $admin = false;

    /**
     * Short help text (will be used in !help)
     *
     * @var string
     */
    public $help = '';

    /**
     * Periodic execution of the command every n seconds
     * If set to null, the command won't be executed periodically
     *
     * Note: Periodic execution can't use Message object since its
     *       not triggered by a message event
     *
     * @var null|int
     */
    public $periodic = null;

    /**
     * Discord instance
     *
     * @var Discord
     */
    protected $discord;

    /**
     * Configuration repository
     *
     * @var array
     */
    protected $config;

    /**
     * @var Message
     */
    protected $message;

    /**
     * Command constructor.
     *
     * @param Bot &$bot
     */
    function __construct(Bot &$bot)
    {
        $this->bot = $bot;
        $this->discord = $bot->getDiscord();
        $this->config = $bot->getConfig();

        echo 'New command registered: ' . get_class($this) . PHP_EOL;
    }

    /**
     * Keyword detection
     *
     * @param Message $message
     * @return bool
     */
    public function triggersOn(Message $message): bool
    {
        $key = strtolower(explode(' ', $message->content)[0]);

        if (is_array($this->keywords) && in_array($key, $this->keywords)) {
            $this->message = $message;

            return true;
        } elseif ($key == $this->keywords) {
            $this->message = $message;

            return true;
        }

        return false;
    }

    /**
     * @return bool
     */
    public function start(): bool
    {
        if ($this->checkAdmin() === false) {
            return false;
        }

        $this->execute();
    }

    /**
     * Check if the command requires admin rights, and if so,
     * check if the user is authorized
     *
     * @return bool
     */
    public function checkAdmin()
    {
        if ($this->admin === false) {
            return true;
        }

        return $this->isAdmin();
    }


    /**
     * Check if the author is an admin
     *
     * @return bool
     */
    public function isAdmin(): bool
    {
        return in_array($this->message->author->user->id, $this->config['admin']);
    }

    /**
     * Abstract command to be implemented in child commands
     *
     * @return mixed
     */
    abstract protected function execute();

    /**
     * Send a message on the triggering channel
     *
     * @param $string
     */
    public function send(string $string): void
    {
        $this->message->channel->sendMessage($string);
    }

    /**
     * Reply to the user
     *
     * @param string $string
     */
    public function reply(string $string): void
    {
        $this->message->reply($string);
    }

    /**
     * Send a message to all channels configured as 'broadcast'
     *
     * @param string $string
     */
    public function broadcast(string $string): void
    {
        foreach ($this->config['broadcast'] as $guild => $channels) {
            foreach ($channels as $channel) {
                $this->discord
                    ->guilds->get('id', $guild)
                    ->channels->get('id', $channel)
                    ->sendMessage($string);
            }
        }
    }
}
<commit_msg>Removed void returns (available only in PHP7.1)<commit_after><?php

namespace Bot\Commands;

use Bot\Bot;
use Discord\Discord;
use Discord\Parts\Channel\Message;

abstract class BaseCommand
{
    /**
     * Keywords that will trigger the command
     *
     * @var string|array
     */
    public $keywords = [];

    /**
     * Determine if only admins can use the command
     *
     * @var bool
     */
    public $admin = false;

    /**
     * Short help text (will be used in !help)
     *
     * @var string
     */
    public $help = '';

    /**
     * Periodic execution of the command every n seconds
     * If set to null, the command won't be executed periodically
     *
     * Note: Periodic execution can't use Message object since its
     *       not triggered by a message event
     *
     * @var null|int
     */
    public $periodic = null;

    /**
     * Discord instance
     *
     * @var Discord
     */
    protected $discord;

    /**
     * Configuration repository
     *
     * @var array
     */
    protected $config;

    /**
     * @var Message
     */
    protected $message;

    /**
     * Command constructor.
     *
     * @param Bot &$bot
     */
    function __construct(Bot &$bot)
    {
        $this->bot = $bot;
        $this->discord = $bot->getDiscord();
        $this->config = $bot->getConfig();

        echo 'New command registered: ' . get_class($this) . PHP_EOL;
    }

    /**
     * Keyword detection
     *
     * @param Message $message
     * @return bool
     */
    public function triggersOn(Message $message): bool
    {
        $key = strtolower(explode(' ', $message->content)[0]);

        if (is_array($this->keywords) && in_array($key, $this->keywords)) {
            $this->message = $message;

            return true;
        } elseif ($key == $this->keywords) {
            $this->message = $message;

            return true;
        }

        return false;
    }

    /**
     * @return bool
     */
    public function start(): bool
    {
        if ($this->checkAdmin() === false) {
            return false;
        }

        $this->execute();
    }

    /**
     * Check if the command requires admin rights, and if so,
     * check if the user is authorized
     *
     * @return bool
     */
    public function checkAdmin()
    {
        if ($this->admin === false) {
            return true;
        }

        return $this->isAdmin();
    }


    /**
     * Check if the author is an admin
     *
     * @return bool
     */
    public function isAdmin(): bool
    {
        return in_array($this->message->author->user->id, $this->config['admin']);
    }

    /**
     * Abstract command to be implemented in child commands
     *
     * @return mixed
     */
    abstract protected function execute();

    /**
     * Send a message on the triggering channel
     *
     * @param $string
     */
    public function send(string $string)
    {
        $this->message->channel->sendMessage($string);
    }

    /**
     * Reply to the user
     *
     * @param string $string
     */
    public function reply(string $string)
    {
        $this->message->reply($string);
    }

    /**
     * Send a message to all channels configured as 'broadcast'
     *
     * @param string $string
     */
    public function broadcast(string $string)
    {
        foreach ($this->config['broadcast'] as $guild => $channels) {
            foreach ($channels as $channel) {
                $this->discord
                    ->guilds->get('id', $guild)
                    ->channels->get('id', $channel)
                    ->sendMessage($string);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.12942144228132713, 'fraction_numerical': 0.0005483959418700301, 'mean_word_length': 1.6479128856624319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7530403', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2050, 'n_words': 569}