From fe15cfb164a1f30af43315696130b45c43d28457 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 23 Mar 2017 12:19:12 -0400 Subject: [PATCH] load joke files into memory on startup, fix is_dm method --- bot.php | 16 +++++++++------- util_fns.php | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bot.php b/bot.php index a9d58df..8e6c031 100644 --- a/bot.php +++ b/bot.php @@ -21,6 +21,9 @@ include __DIR__.'/kaomoji.php'; include __DIR__.'/definitions.php'; include __DIR__.'/util_fns.php'; +$yomamajokes = file("yomamajokes.txt"); +$jokes = explode("-----------------------------------------------------------------------------", file_get_contents(__DIR__.'/miscjokes.txt')); + $starttime = Carbon::now(); $defs = new Definitions(__DIR__.'/definitions.json'); $imgs = new Definitions(__DIR__.'/img_urls.json'); @@ -40,7 +43,7 @@ $discord = new DiscordCommandClient([ $game = $discord->factory(Game::class, [ - 'name' => 'with myself... type ;help for more info', + 'name' => ';help for more info', ]); @@ -71,6 +74,7 @@ $discord->on('ready', function($discord) use ($game, $defs, $imgs, $starttime) { if (is_dm($msg)) { if (!$msg->author->bot){ + $msg->channel->broadcastTyping(); ask_cleverbot(implode(" ", $args))->then(function($result) use ($msg) { send($msg, $result->output); }); @@ -618,9 +622,8 @@ register_help('kaomoji'); /////////////////////////////////////////////////////////// -$joke = $discord->registerCommand('joke', function($msg, $args) { - $joke_arr = explode("-----------------------------------------------------------------------------", file_get_contents(__DIR__.'/miscjokes.txt')); - send($msg, $joke_arr[array_rand($joke_arr)]); +$joke = $discord->registerCommand('joke', function($msg, $args) use ($jokes) { + send($msg, $jokes[array_rand($jokes)]); }, [ 'description' => 'tells a random joke', 'usage' => '', @@ -645,9 +648,8 @@ register_help('joke'); ], ]); - $joke->registerSubCommand('yomama', function($msg, $args) { - $jokes = file("yomamajokes.txt"); - send($msg, $jokes[array_rand($jokes)]); + $joke->registerSubCommand('yomama', function($msg, $args) use ($yomamajokes) { + send($msg, $yomamajokes[array_rand($yomamajokes)]); }, [ 'description' => 'yo mama jokes', 'aliases' => [ diff --git a/util_fns.php b/util_fns.php index 24485f0..b865047 100644 --- a/util_fns.php +++ b/util_fns.php @@ -34,7 +34,8 @@ function sendfile($msg, $filepath, $filename, $txt) { function is_dm($msg) { - return $msg->author instanceOf Discord\Parts\User\User; + return $msg->channel->is_private; + // return $msg->author instanceOf Discord\Parts\User\User; }