tictactoe deletes old msgs

This commit is contained in:
Ben Harris 2017-04-29 14:54:48 -04:00
parent 5581dcdd8c
commit 90b91fa21d
3 changed files with 100 additions and 9 deletions

View File

@ -2,6 +2,7 @@
namespace BenBot\Commands;
use BenBot\Utils;
use BenBot\EmbedColors;
use Discord\Parts\Embed\Embed;
use Carbon\Carbon;
@ -44,6 +45,17 @@ class Debug
'role'
],
]);
self::$bot->registerCommand('whois', [__CLASS__, 'userInfo'], [
'description' => 'get info about a user',
'usage' => '[@user]',
'aliases' => [
'user',
'info',
'userinfo',
'whoami',
],
]);
echo __CLASS__ . " registered", PHP_EOL;
}
@ -98,7 +110,7 @@ class Debug
$usercount += $guild->member_count;
}
$url = "http://test.benharris.ch/phpsysinfo/xml.php?plugin=complete&json";
$url = "http://test.benharr.is/phpsysinfo/xml.php?plugin=complete&json";
self::$bot->http->get($url, null, [], false)->then(function ($result) use ($msg, $usercount) {
print_r($result);
$vitals = $result->Vitals->{"@attributes"};
@ -106,6 +118,7 @@ class Debug
$embed = self::$bot->factory(Embed::class, [
'title' => 'Benbot status',
'thumbnail' => ['url' => self::$bot->avatar],
'color' => EmbedColor::BLUE,
'fields' => [
['name' => 'Server Uptime'
,'value' => Utils::secondsConvert($vitals->Uptime)
@ -154,9 +167,10 @@ class Debug
'thumbnail' => [
'url' => $guild->icon
],
'color' => EmbedColors::BLUE,
'fields' => [
['name' => 'Owner'
,'value' => "@{$guild->owner->username}#{$guild->owner->discriminator}"
,'value' => "$guild->owner"
,'inline' => true
],
['name' => 'Region'
@ -202,5 +216,52 @@ class Debug
}
public static function userInfo($msg, $args)
{
if (Utils::isDM($msg)) {
return "you're not in a server, silly";
}
$users = [];
if (count($msg->mentions) === 0) {
$users[] = $msg->author;
} else {
foreach ($msg->mentions as $mention) {
$users[] = $msg->channel->guild->members->get('id', $mention->id);
}
}
foreach ($users as $user) {
$roles = [];
foreach ($user->roles as $role) {
$roles[] = $role->name;
}
$embed = self::$bot->factory(Embed::class, [
'title' => "User info for",
'description' => "$user",
'thumbnail' => ['url' => $user->user->avatar],
'color' => EmbedColors::BLUE,
'fields' => [
['name' => 'Roles'
,'value' => implode(", ", $roles)
],
['name' => 'ID'
,'value' => $user->id
],
['name' => 'Status'
,'value' => $user->status
],
['name' => 'Game'
,'value' => $user->game->name ?? 'not playing anything right now'
],
['name' => 'Member since'
,'value' => $user->joined_at->format('g:i A \o\n l F j, Y') . " ({$user->joined_at->diffForHumans()})"
],
],
'timestamp' => null,
]);
Utils::send($msg, "", $embed);
}
}
}

View File

@ -12,10 +12,6 @@ class TicTacToe
{
self::$bot = $that;
self::$bot->tictactoe[] = [
'active' => false
];
$tic = self::$bot->registerCommand('tic', [__CLASS__, 'startGame'], [
'description' => 'play tic tac toe!',
'usage' => '<@user>',
@ -70,7 +66,10 @@ class TicTacToe
foreach ($msg->mentions as $mention) {
self::$bot->tictactoe[$gameid]['players'][":o:"] = $mention->id;
}
Utils::send($msg, self::printBoard($gameid) . "\n<@" . self::$bot->tictactoe[$gameid]['players'][self::$bot->tictactoe[$gameid]['turn']] . ">, it's your turn!");
Utils::send($msg, self::printBoard($gameid) . "\n<@" . self::$bot->tictactoe[$gameid]['players'][self::$bot->tictactoe[$gameid]['turn']] . ">, it's your turn!")->then(function ($result) use ($gameid, $msg) {
self::$bot->tictactoe[$gameid]['last_msg'] = $result;
Utils::deleteMessage($msg);
});
} else {
return "can't play tictactoe with more than two people!";
}
@ -99,10 +98,14 @@ class TicTacToe
return;
}
if ($move > 0 && $move < 10) {
Utils::send($msg, self::doMove($gameid, $player, $move));
Utils::deleteMessage(self::$bot->tictactoe[$gameid]['last_msg']);
Utils::send($msg, self::doMove($gameid, $player, $move))->then(function ($result) use ($gameid, $msg) {
self::$bot->tictactoe[$gameid]['last_msg'] = $result;
Utils::deleteMessage($msg);
});
return;
} else {
Utils::send($msg, "invalid move. enter a number 1-9 or quit with `;tic stop`");
Utils::send($msg, "invalid move. enter a number 1-9 or quit with `;tic stop`\n" . self::printBoard($gameid));
return;
}
}

27
src/EmbedColors.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace BenBot;
class EmbedColors
{
const DEFAULT = 0;
const AQUA = 1752220;
const GREEN = 3066993;
const BLUE = 3447003;
const PURPLE = 10181046;
const GOLD = 15844367;
const ORANGE = 15105570;
const RED = 15158332;
const GREY = 9807270;
const DARKER_GREY = 8359053;
const NAVY = 3426654;
const DARK_AQUA = 1146986;
const DARK_GREEN = 2067276;
const DARK_BLUE = 2123412;
const DARK_PURPLE = 7419530;
const DARK_GOLD = 12745742;
const DARK_ORANGE = 11027200;
const DARK_RED = 10038562;
const DARK_GREY = 9936031;
const LIGHT_GREY = 12370112;
const DARK_NAVY = 2899536;
}