/**
  * @param Request $request
  */
 protected function renderStats(Request $request)
 {
     $users = $this->getUsers();
     $data = ['servers' => count($request->getDiscord()->client->guilds), 'channels' => $this->getChannelCount(), 'users' => $users->count(), 'online' => count($users->filter(function (Member $user) {
         return $user->status !== 'offline';
     })), 'channel' => $request->isPrivateMessage() ? [] : ['channels' => count($request->getServer()->channels), 'users' => count($request->getServer()->members), 'online' => count($request->getServer()->getMembersAttribute()->filter(function (Member $user) {
         return $user->status !== 'offline';
     }))]];
     $request->reply($request->renderTemplate('@Core/stats.twig', $data));
 }
    /**
     * @param Request $request
     * @param array   $matches
     *
     * @return \React\EventLoop\Timer\Timer|\React\EventLoop\Timer\TimerInterface
     */
    protected function evalCode(Request $request, array $matches = [])
    {
        $request->deleteMessage($request->getMessage())->then(function () use($request, $matches) {
            $request->reply('Executing Code')->then(function (Message $message) use($request, $matches) {
                // Lets set some local variables for the eval
                $client = $this->getDiscord();
                $container = $this->container;
                $server = $request->getServer();
                $author = $request->getAuthor();
                $channel = $request->getChannel();
                $self = $this;
                $start = microtime(true);
                $_____responseContent = <<<'EOF'
```php
# Executed the following code in %d ms
%s

# Resulted in the following:
%s

```
EOF;
                $sprintf = [];
                $sprintf[] = $matches[2];
                try {
                    if ($matches[1] === ' --raw') {
                        $response = eval($matches[2]);
                        var_dump($response);
                    } else {
                        $language = new ExpressionLanguage();
                        $sprintf[0] = $language->compile($matches[2], array_keys(get_defined_vars())) . ' (' . $matches[2] . ')';
                        $response = @$language->evaluate($matches[2], get_defined_vars());
                    }
                } catch (\Exception $e) {
                    $sprintf[] = $e->getMessage() . ' on line ' . $e->getLine() . ' in file ' . $e->getFile();
                    $sprintf[] = (microtime(true) - $start) * 1000;
                    return $request->updateMessage($message, sprintf($_____responseContent, $sprintf[2], $sprintf[0], $sprintf[1]));
                }
                if (is_array($response) || is_object($response)) {
                    $response = json_decode($response, true);
                }
                $sprintf[] = $response;
                $sprintf[] = (microtime(true) - $start) * 1000;
                $request->updateMessage($message, sprintf($_____responseContent, $sprintf[2], $sprintf[0], $sprintf[1]));
            });
        });
    }
 /**
  * @param Request $request
  * @param array   $matches
  */
 protected function renderHelpItem(Request $request, array $matches)
 {
     $modules = $this->getModuleCommands();
     foreach ($modules as $name => $commands) {
         /** @var AbstractBotCommand[] $commands */
         foreach ($commands as $command) {
             if ($command->isEnabled()) {
                 if ($command->getName() === $matches[1]) {
                     if (!empty($command->getHelp())) {
                         $request->reply($command->getHelp());
                     }
                     return;
                 }
             }
         }
     }
 }
 /**
  * @param Request $request
  * @param array   $matches
  *
  * @return bool|ServerModule|mixed|null
  */
 private function getServerModule(Request $request, array $matches)
 {
     $moduleName = $matches[2];
     $server = $request->getServerManager()->getDatabaseServer();
     $serverModule = null;
     foreach ($server->getModules() as $item) {
         $name = strtolower(str_replace('Module', '', $item->getModule()->getName()));
         if ($name === strtolower($moduleName)) {
             $serverModule = $item;
             break;
         }
     }
     if (empty($serverModule)) {
         $request->reply("\"{$moduleName}\" is not a valid module name.");
         return false;
     }
     if (!$serverModule->getModule()->isDisableable()) {
         $request->reply("\"{$moduleName}\" is not disableable.");
         return false;
     }
     return $serverModule;
 }
 /**
  * @param Request $request
  * @param array   $matches
  */
 protected function toggleIgnore(Request $request, array $matches)
 {
     $ignore = $this->setIgnored(empty($matches[1]), $matches[2], $matches[3]);
     $request->reply($ignore ? 'Ignored' : 'Unignored');
 }