added more commands
This commit is contained in:
parent
04f63e4641
commit
1e4cdbd9a9
|
@ -10,6 +10,7 @@ use BenBot\Utils;
|
|||
use BenBot\SerializedArray;
|
||||
use BenBot\Command;
|
||||
use BenBot\Commands;
|
||||
use BenBot\FontConverter;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
@ -27,6 +28,7 @@ class BenBot extends Discord {
|
|||
public $emails;
|
||||
public $jokes;
|
||||
public $yomamajokes;
|
||||
public $copypastas;
|
||||
|
||||
protected $help;
|
||||
protected $game;
|
||||
|
@ -48,6 +50,7 @@ class BenBot extends Discord {
|
|||
$this->dir = $dir;
|
||||
$this->help = [];
|
||||
$this->jokes = explode("---", file_get_contents("$dir/miscjokes.txt"));
|
||||
$this->copypastas = explode("---", file_get_contents("$dir/copypasta.txt"));
|
||||
$this->yomamajokes = file("$dir/yomamajokes.txt");
|
||||
|
||||
|
||||
|
@ -66,6 +69,7 @@ class BenBot extends Discord {
|
|||
|
||||
$this->on('ready', function () {
|
||||
Utils::init($this);
|
||||
FontConverter::init();
|
||||
$this->updatePresence($this->game);
|
||||
|
||||
$this->on('message', function ($msg) {
|
||||
|
@ -86,6 +90,20 @@ class BenBot extends Discord {
|
|||
}
|
||||
|
||||
|
||||
// make sure stringys are strings
|
||||
foreach ($args as $key => $arg) {
|
||||
$args[$key] = (string) $arg;
|
||||
}
|
||||
|
||||
// do the font stuff!
|
||||
if (array_key_exists($cmd, FontConverter::$fonts)) {
|
||||
Utils::send($msg, FontConverter::$cmd(implode(" ", $args)) . "\n--{$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// look up command
|
||||
if (array_key_exists($cmd, $this->cmds)) {
|
||||
$command = $this->cmds[$cmd];
|
||||
|
@ -95,10 +113,6 @@ class BenBot extends Discord {
|
|||
return;
|
||||
}
|
||||
|
||||
// make sure stringys are strings
|
||||
foreach ($args as $key => $arg) {
|
||||
$args[$key] = (string) $arg;
|
||||
}
|
||||
// do the command
|
||||
$result = $command->handle($msg, $args);
|
||||
|
||||
|
@ -106,15 +120,16 @@ class BenBot extends Discord {
|
|||
if (is_string($result)) {
|
||||
Utils::send($msg, $result);
|
||||
}
|
||||
|
||||
} elseif (Utils::isDM($msg)) {
|
||||
$msg->channel->broadcastTyping();
|
||||
Commands\CleverBot::askCleverbot((string) $str)->then(function ($result) use ($msg) {
|
||||
Utils::send($msg, $result->output);
|
||||
}, function ($e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
});
|
||||
}
|
||||
|
||||
} elseif (Utils::isDM($msg)) {
|
||||
$msg->channel->broadcastTyping();
|
||||
Utils::askCleverbot($str)->then(function ($result) use ($msg) {
|
||||
Utils::send($msg, $result->output);
|
||||
}, function ($e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,7 +173,7 @@ class BenBot extends Discord {
|
|||
$this->registerAllCommands();
|
||||
|
||||
Utils::ping("bot started successfully");
|
||||
echo PHP_EOL, "BOT STARTED SUCCESSFULLY", PHP_EOL;
|
||||
echo PHP_EOL, "BOT STARTED SUCCESSFULLY", PHP_EOL, PHP_EOL;
|
||||
|
||||
});
|
||||
|
||||
|
@ -166,12 +181,16 @@ class BenBot extends Discord {
|
|||
|
||||
|
||||
|
||||
|
||||
public function registerAllCommands()
|
||||
{
|
||||
Commands\Fun::register($this);
|
||||
Commands\CleverBot::register($this);
|
||||
Commands\Debug::register($this);
|
||||
Commands\Misc::register($this);
|
||||
Commands\Definitions::register($this);
|
||||
Commands\Fonts::register($this);
|
||||
Commands\Fun::register($this);
|
||||
Commands\Jokes::register($this);
|
||||
Commands\Misc::register($this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
use React\Promise\Deferred;
|
||||
|
||||
class CleverBot {
|
||||
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
self::$bot->registerCommand('chat', [__CLASS__, 'chat'], [
|
||||
'description' => 'talk to benbot',
|
||||
'usage' => '<what you want to say>',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'',
|
||||
'cleverbot',
|
||||
],
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function chat($msg, $args)
|
||||
{
|
||||
$msg->channel->broadcastTyping();
|
||||
self::askCleverbot(implode(" ", $args))->then(function ($result) use ($msg) {
|
||||
Utils::send($msg, $result->output);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function askCleverbot($input)
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$url = "https://www.cleverbot.com/getreply";
|
||||
$key = getenv('CLEVERBOT_API_KEY');
|
||||
$input = rawurlencode($input);
|
||||
self::$bot->http->get("$url?input=$input&key=$key", null, [], false)->then(function ($apidata) use ($deferred) {
|
||||
$deferred->resolve($apidata);
|
||||
}, function ($e) {
|
||||
$deferred->reject($e);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,11 @@
|
|||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Discord\Parts\Embed\Embed;
|
||||
use function Stringy\create as s;
|
||||
|
||||
class Debug {
|
||||
|
||||
|
@ -11,15 +15,179 @@ class Debug {
|
|||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
self::$bot->registerCommand('up', [__CLASS__, 'up'], [
|
||||
'description' => 'shows uptime',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('dbg', [__CLASS__, 'dbg'], [
|
||||
'description' => 'logs message details',
|
||||
]);
|
||||
self::$bot->registerCommand('sys', [__CLASS__, 'sys'], [
|
||||
'description' => 'run server command and show output',
|
||||
]);
|
||||
self::$bot->registerCommand('status', [__CLASS__, 'status'], [
|
||||
'description' => 'get status of bot and server',
|
||||
]);
|
||||
self::$bot->registerCommand('server', [__CLASS__, 'server'], [
|
||||
'description' => 'displays information about the server',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'guild',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('roles', [__CLASS__, 'roles'], [
|
||||
'description' => 'lists all roles in the server',
|
||||
'aliases' => [
|
||||
'role'
|
||||
],
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
public static function up($msg, $args)
|
||||
{
|
||||
return "benbot has been up for " . self::$bot->start_time->diffForHumans(Carbon::now(), true);
|
||||
}
|
||||
|
||||
|
||||
public static function dbg($msg, $args)
|
||||
{
|
||||
if (Utils::getUserIDFromMsg($msg) == "193011352275648514") {
|
||||
print_r($msg);
|
||||
Utils::send($msg, "check logs!")->then(function ($result) {
|
||||
self::$bot->loop->addTimer(3, function ($timer) use ($result) {
|
||||
Utils::deleteMessage($result);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return "**you're not allowed to use that command**";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function sys($msg, $args)
|
||||
{
|
||||
if (Utils::getUserIDFromMsg($msg) == "193011352275648514") {
|
||||
return "```" . shell_exec(implode(" ", $args)) . "```";
|
||||
} else {
|
||||
return "**you're not allowed to use that command**";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function status($msg, $args)
|
||||
{
|
||||
$usercount = 0;
|
||||
foreach (self::$bot->guilds as $guild) {
|
||||
$usercount += $guild->member_count;
|
||||
}
|
||||
|
||||
$url = "http://test.benharris.ch/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"};
|
||||
|
||||
$embed = self::$bot->factory(Embed::class, [
|
||||
'title' => 'Benbot status',
|
||||
'thumbnail' => ['url' => self::$bot->avatar],
|
||||
'fields' => [
|
||||
['name' => 'Server Uptime'
|
||||
,'value' => Utils::secondsConvert($vitals->Uptime)
|
||||
],
|
||||
['name' => 'Bot Uptime'
|
||||
,'value' => self::$bot->start_time->diffForHumans(Carbon::now(), true)
|
||||
],
|
||||
['name' => 'Server Load Average'
|
||||
,'value' => $vitals->LoadAvg
|
||||
],
|
||||
['name' => 'Bot Server Count'
|
||||
,'value' => count(self::$bot->guilds)
|
||||
],
|
||||
['name' => 'User Count'
|
||||
,'value' => $usercount
|
||||
],
|
||||
['name' => 'Bot Memory Usage'
|
||||
,'value' => Utils::convertMemoryUsage()
|
||||
],
|
||||
],
|
||||
'timestamp' => null,
|
||||
]);
|
||||
|
||||
Utils::send($msg, "", $embed);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function server($msg, $args)
|
||||
{
|
||||
if (Utils::isDM($msg)) {
|
||||
return "you're not in a server, silly";
|
||||
}
|
||||
|
||||
$verification_levels = [
|
||||
0 => "None: must have discord account",
|
||||
1 => "Low: must have verified email",
|
||||
2 => "Medium: must have verified email for more than 5 minutes",
|
||||
3 => "(╯°□°)╯︵ ┻━┻: must have verified email, be registered on discord for more than 5 minutes, and must wait 10 minutes before speaking in any channel",
|
||||
];
|
||||
$guild = $msg->channel->guild;
|
||||
$created_at = Carbon::createFromTimestamp(Utils::timestampFromSnowflake($guild->id));
|
||||
|
||||
$embed = self::$bot->factory(Embed::class, [
|
||||
'title' => "{$guild->name} server info",
|
||||
'thumbnail' => [
|
||||
'url' => $guild->icon
|
||||
],
|
||||
'fields' => [
|
||||
['name' => 'Owner'
|
||||
,'value' => "@{$guild->owner->username}#{$guild->owner->discriminator}"
|
||||
,'inline' => true
|
||||
],
|
||||
['name' => 'Region'
|
||||
,'value' => $guild->region
|
||||
,'inline' => true
|
||||
],
|
||||
['name' => 'Member Count'
|
||||
,'value' => $guild->member_count
|
||||
,'inline' => true
|
||||
],
|
||||
['name' => 'Channel Count'
|
||||
,'value' => count($guild->channels)
|
||||
,'inline' => true
|
||||
],
|
||||
['name' => 'Server Created'
|
||||
,'value' => $created_at->format('g:i A \o\n l F j, Y') . " (" . $created_at->diffForHumans() . ")"
|
||||
],
|
||||
['name' => 'Verification level'
|
||||
,'value' => $verification_levels[$guild->verification_level]
|
||||
],
|
||||
['name' => 'Server ID'
|
||||
,'value' => $guild->id
|
||||
],
|
||||
['name' => 'benbot joined'
|
||||
,'value' => $guild->joined_at->format('g:i A \o\n l F j, Y') . " (" . $guild->joined_at->diffForHumans() . ")"
|
||||
],
|
||||
],
|
||||
'timestamp' => null,
|
||||
]);
|
||||
Utils::send($msg, "", $embed);
|
||||
}
|
||||
|
||||
|
||||
public static function roles($msg, $args)
|
||||
{
|
||||
$guild = $msg->channel->guild;
|
||||
$response = "```roles for {$guild->name}\n\n";
|
||||
foreach ($guild->roles as $role) {
|
||||
$response .= "{$role->name} ({$role->id})\n";
|
||||
}
|
||||
$response .= "```";
|
||||
Utils::send($msg, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
use function String\create as s;
|
||||
|
||||
class Definitions {
|
||||
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
self::$bot->registerCommand('set', [__CLASS__, 'setDef'], [
|
||||
'description' => 'sets this to that',
|
||||
'usage' => '<this> <that>',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'define',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('get', [__CLASS__, 'getDef'], [
|
||||
'description' => 'retrieve a definition',
|
||||
'usage' => '<thing to find>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('unset', [__CLASS__, 'unsetDef'], [
|
||||
'description' => 'remove a definition',
|
||||
'usage' => '<thing to remove>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('listdefs', [__CLASS__, 'listDefs'], [
|
||||
'description' => 'sends all definitions to DM',
|
||||
]);
|
||||
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function setDef($msg, $args)
|
||||
{
|
||||
$def = strtolower(array_shift($args));
|
||||
if ($def == "san" && $msg->author->id != 190933157430689792) {
|
||||
return "you're not san...";
|
||||
}
|
||||
self::$bot->defs[$def] = implode(" ", $args);
|
||||
Utils::send($msg, $def . " set to: " . implode(" ", $args))->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
self::$bot->loop->addTimer(5, function ($timer) use ($result) {
|
||||
Utils::deleteMessage($result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static function getDef($msg, $args)
|
||||
{
|
||||
if (isset($args[0])) {
|
||||
$def = strtolower($args[0]);
|
||||
if (isset(self::$bot->defs[$def])) {
|
||||
Utils::send($msg, "**$def**: " . self::$bot->defs[$def])->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
} else {
|
||||
Utils::send($msg, "definition not found. you can set it with `;set $def <definition here>`");
|
||||
}
|
||||
} else {
|
||||
return "tell me what definition you want! type `;listdefs` and I'll send you all current definitions in a dm";
|
||||
}
|
||||
}
|
||||
|
||||
public static function unsetDef($msg, $args)
|
||||
{
|
||||
if (isset($args[0])) {
|
||||
$def = strtolower($args[0]);
|
||||
if (isset(self::$bot->defs[$def])) {
|
||||
unset(self::$bot->defs[$def]);
|
||||
} else {
|
||||
return "doesn't exist... aborting.";
|
||||
}
|
||||
return "$def removed";
|
||||
}
|
||||
}
|
||||
|
||||
public static function listDefs($msg, $args)
|
||||
{
|
||||
$response = "available definitions:\n\n";
|
||||
|
||||
foreach (self::$bot->defs as $name => $def) {
|
||||
$response .= "**$name**: $def\n";
|
||||
}
|
||||
|
||||
if (strlen($response) > 2000) {
|
||||
foreach (str_split($response, 2000) as $part) {
|
||||
$msg->author->user->sendMessage($part);
|
||||
}
|
||||
} else {
|
||||
$msg->author->user->sendMessage($response);
|
||||
}
|
||||
|
||||
Utils::send($msg, "{$msg->author}, check DMs!")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
self::$bot->loop->addTimer(5, function ($timer) use ($result) {
|
||||
Utils::deleteMessage($result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
|
||||
class Emails {
|
||||
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\FontConverter;
|
||||
use BenBot\Utils;
|
||||
|
||||
class Fonts {
|
||||
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
self::$bot->registerCommand('fontlist', [__CLASS__, 'fontlist'], [
|
||||
'description' => 'change your message to another font',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'listfonts',
|
||||
'font',
|
||||
'text',
|
||||
'fonts',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('block', [__CLASS__, 'blockText'], [
|
||||
'description' => 'block text',
|
||||
'usage' => '<msg>',
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
public static function fontlist($msg, $args)
|
||||
{
|
||||
return "available fonts:\n```" . implode(", ", array_keys(FontConverter::$fonts)) . "```use the name of the font as a command";
|
||||
}
|
||||
|
||||
public static function blockText($msg, $args)
|
||||
{
|
||||
Utils::send($msg, FontConverter::blockText(implode(" ", $args)) . "\n--{$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
use BenBot\Utils;
|
||||
|
||||
class Fun {
|
||||
|
||||
|
@ -9,16 +12,176 @@ class Fun {
|
|||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
self::$bot->registerCommand('roll', [__CLASS__, 'rollDie'], [
|
||||
'description' => 'rolls an n-sided die',
|
||||
'usage' => '<number of sides>',
|
||||
'description' => 'rolls an n-sided die',
|
||||
'usage' => '<number of sides>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('8ball', [__CLASS__, 'ask8Ball'], [
|
||||
'description' => 'ask the mighty 8-ball',
|
||||
'usage' => '<your question to ask here>',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'8b',
|
||||
'fortune',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('lenny', [__CLASS__, 'lennyFace'], [
|
||||
'description' => 'you should know what this does',
|
||||
]);
|
||||
self::$bot->registerCommand('shrug', [__CLASS__, 'shrugGuy'], [
|
||||
'description' => 'meh',
|
||||
'aliases' => [
|
||||
'meh',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('noice', [__CLASS__, 'noice'], [
|
||||
'description' => 'ayy lmao',
|
||||
]);
|
||||
self::$bot->registerCommand('copypasta', [__CLASS__, 'copyPasta'], [
|
||||
'description' => 'get random copypasta',
|
||||
]);
|
||||
self::$bot->registerCommand('kaomoji', [__CLASS__, 'kaomoji'], [
|
||||
'description' => 'shows a cool japanese emoji face thing',
|
||||
'usage' => '<sad|happy|angry|confused|surprised>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('bamboozle', [__CLASS__, 'bamboozle'], [
|
||||
'description' => 'bamboozled again',
|
||||
'usage' => '<@user>',
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function rollDie($msg, $args)
|
||||
{
|
||||
return "{$msg->author}, you rolled a " . rand(1, $args[0] ?? 6);
|
||||
}
|
||||
|
||||
public static function ask8Ball($msg, $args)
|
||||
{
|
||||
$fortunes = [
|
||||
"It is certain",
|
||||
"It is decidedly so",
|
||||
"Without a doubt",
|
||||
"Yes definitely",
|
||||
"You may rely on it",
|
||||
"As I see it, yes",
|
||||
"Most likely",
|
||||
"Outlook good",
|
||||
"Yes",
|
||||
"Signs point to yes",
|
||||
"Reply hazy try again",
|
||||
"Ask again later",
|
||||
"Better not tell you now",
|
||||
"Cannot predict now",
|
||||
"Concentrate and ask again",
|
||||
"Don't count on it",
|
||||
"My reply is no",
|
||||
"My sources say no",
|
||||
"Outlook not so good",
|
||||
"Very doubtful",
|
||||
];
|
||||
|
||||
if (count($args > 0)) {
|
||||
$response = "Your question: *" . implode(" ", $args) . "*\n\n**";
|
||||
$response .= $fortunes[array_rand($fortunes)] . "**";
|
||||
Utils::send($msg, $response)->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
} else {
|
||||
return "{$msg->author}, you have to ask a question!";
|
||||
}
|
||||
}
|
||||
|
||||
public static function lennyFace($msg, $args)
|
||||
{
|
||||
echo "lenny", PHP_EOL;
|
||||
Utils::send($msg, "( ͡° ͜ʖ ͡°)\n--{$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
public static function shrugGuy($msg, $args)
|
||||
{
|
||||
echo "meh", PHP_EOL;
|
||||
Utils::send($msg, "¯\\\_(ツ)\_/¯")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
public static function noice($msg, $args)
|
||||
{
|
||||
$bs = "
|
||||
:ok_hand: :joy:
|
||||
:ok_hand::joy:
|
||||
:joy:
|
||||
:joy::ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:ok_hand:
|
||||
:ok_hand: :joy:
|
||||
:ok_hand: :joy:
|
||||
:ok_hand: :joy:
|
||||
:ok_hand: :joy:
|
||||
:ok_hand::joy:
|
||||
:joy:
|
||||
:joy::ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:joy: :ok_hand:
|
||||
:ok_hand:";
|
||||
|
||||
Utils::send($msg, $bs)->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
public static function copyPasta($msg, $args)
|
||||
{
|
||||
return self::$bot->copypastas[array_rand(self::$bot->copypastas)];
|
||||
}
|
||||
|
||||
public static function kaomoji($msg, $args)
|
||||
{
|
||||
$kaomojis = [
|
||||
'sad' => ['(ノ_<。)', '(*-_-)', '(´-ω-`)', '.・゚゚・(/ω\)・゚゚・.', '(μ_μ)', '(ノД`)', '(-ω-、)', '。゜゜(´O`) ゜゜。', 'o(TヘTo)', '( ; ω ; )', '(。╯3╰。)', '。・゚゚*(>д<)*゚゚・。', '( ゚,_ゝ`)', '(个_个)', '(╯︵╰,)', '。・゚(゚><゚)゚・。', '( ╥ω╥ )', '(╯_╰)', '(╥_╥)', '.。・゚゚・(>_<)・゚゚・。.', '(/ˍ・、)', '(ノ_<、)', '(╥﹏╥)', '。゚(。ノωヽ。)゚。', '(つω`*)', '(。T ω T。)', '(ノω・、)', '・゚・(。>ω<。)・゚・', '(T_T)', '(>_<)', '(T▽T)', '。゚・ (>﹏<) ・゚。', 'o(〒﹏〒)o', '(。•́︿•̀。)', '(ಥ﹏ಥ)'],
|
||||
'happy' => ['(* ^ ω ^)', '(´ ∀ ` *)', '٩(◕‿◕。)۶', '☆*:.。.o(≧▽≦)o.。.:*☆', '(o^▽^o)', '(⌒▽⌒)☆', '<( ̄︶ ̄)>', 'ヽ(・∀・)ノ', '(´。• ω •。`)', '( ̄ω ̄)', '`;:゛;`;・(°ε° )', '(o・ω・o)', '(@^-^)', 'ヽ(*・ω・)ノ', '(o_ _)ノ彡☆', '(^人^)', '(o´▽`o)', '(*´▽`*)', '。゚( ゚^∀^゚)゚。', '( ´ ω ` )', '(((o(*°▽°*)o)))', '(≧◡≦)', '(o´∀`o)', '(´• ω •`)', '(^▽^)', '(⌒ω⌒)', '∑d(°∀°d)', '╰(▔∀▔)╯', '(─‿‿─)', '(*^‿^*)', 'ヽ(o^―^o)ノ', '(✯◡✯)', '(◕‿◕)', '(*≧ω≦*)', '(☆▽☆)', '(⌒‿⌒)', '\(≧▽≦)/', '⌒(o^▽^o)ノ', '(*°▽°*)', '٩(。•́‿•̀。)۶', '(✧ω✧)', 'ヽ(*⌒▽⌒*)ノ', '(´。• ᵕ •。`)', '( ´ ▽ ` )', '( ̄▽ ̄)', '╰(*´︶`*)╯', 'ヽ(>∀<☆)ノ', 'o(≧▽≦)o', '(☆ω☆)', '(っ˘ω˘ς )', '\( ̄▽ ̄)/', '(*¯︶¯*)', '\(^▽^)/', '٩(◕‿◕)۶', '(o˘◡˘o)', '\(★ω★)/', '\(^ヮ^)/', '(〃^▽^〃)', '(╯✧▽✧)╯', 'o(>ω<)o', 'o( ❛ᴗ❛ )o', '。゚(TヮT)゚。', '( ‾́ ◡ ‾́ )', '(ノ´ヮ`)ノ*: ・゚'],
|
||||
'angry' => ['(#`Д´)', '(`皿´#)', '( ` ω ´ )', 'ヽ( `д´*)ノ', '(・`ω´・)', '(`ー´)', 'ヽ(`⌒´メ)ノ', '凸(`△´#)', '( `ε´ )', 'ψ( ` ∇ ´ )ψ', 'ヾ(`ヘ´)ノ゙', 'ヽ(‵﹏´)ノ', '(メ` ロ ´)', '(╬`益´)', '┌∩┐(◣_◢)┌∩┐', '凸( ` ロ ´ )凸', 'Σ(▼□▼メ)', '(°ㅂ°╬)', 'ψ(▼へ▼メ)~→', '(ノ°益°)ノ', '(҂ `з´ )', '(‡▼益▼)', '(҂` ロ ´)凸', '((╬◣﹏◢))', '٩(╬ʘ益ʘ╬)۶', '(╬ Ò﹏Ó)', '\\٩(๑`^´๑)۶//', '(凸ಠ益ಠ)凸', '↑_(ΦwΦ)Ψ', '←~(Ψ▼ー▼)∈', '୧((#Φ益Φ#))୨', '٩(ఠ益ఠ)۶', '(ノಥ益ಥ)ノ'],
|
||||
'confused' => ['( ̄ω ̄;)', 'σ( ̄、 ̄〃)', '( ̄~ ̄;)', '(-_-;)・・・', '(・_・ヾ', '(〃 ̄ω ̄〃ゞ', '┐( ̄ヘ ̄;)┌', '(・_・;)', '( ̄_ ̄)・・・', '╮( ̄ω ̄;)╭', '( ̄. ̄;)', '(@_@)', '(・・;)ゞ', 'Σ( ̄。 ̄ノ)', '(・・ ) ?', '(•ิ_•ิ)?', '(◎ ◎)ゞ', '(ーー;)', 'ლ(ಠ_ಠ ლ)', 'ლ(¯ロ¯"ლ)'],
|
||||
'surprised' => ['w(°o°)w', 'ヽ(°〇°)ノ', 'Σ(O_O)', 'Σ(°ロ°)', '(⊙_⊙)', '(o_O)', '(O_O;)', '(O.O)', '(°ロ°) !', '(o_O) !', '(□_□)', 'Σ(□_□)', '∑(O_O;)', '( : ౦ ‸ ౦ : )'],
|
||||
'embarrassed' => ['(⌒_⌒;)', '(o^ ^o)', '(*/ω\)', '(*/。\)', '(*/_\)', '(*ノωノ)', '(o-_-o)', '(*μ_μ)', '( ◡‿◡ *)', '(ᵔ.ᵔ)', '(//ω//)', '(ノ*°▽°*)', '(*^.^*)', '(*ノ▽ノ)', '( ̄▽ ̄*)ゞ', '(⁄ ⁄•⁄ω⁄•⁄ ⁄)', '(*/▽\*)', '(⁄ ⁄>⁄ ▽ ⁄<⁄ ⁄)'],
|
||||
];
|
||||
|
||||
if (isset($args[0]) && isset($kaomojis[$args[0]])) {
|
||||
Utils::send($msg, $kaomojis[$args[0]][array_rand($kaomojis[$args[0]])] . "\n\n--{$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
} else {
|
||||
$allkaomojis = Utils::arrayFlatten($kaomojis);
|
||||
Utils::send($msg, $allkaomojis[array_rand($allkaomojis)] . "\n\n--{$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static function bamboozle($msg, $args)
|
||||
{
|
||||
$response = count($msg->mentions) > 0 ? implode(", ", array_keys($msg->mentions)) : $msg->author;
|
||||
$response .= ", you've been heccin' bamboozled again!!!!!!!!!!!!!!!!!!!!!!!!";
|
||||
Utils::sendFile($msg, 'img/bamboozled.jpg', 'bamboozle.jpg', $response)->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ namespace BenBot\Commands;
|
|||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
use function Stringy\create as s;
|
||||
|
||||
class Misc {
|
||||
|
||||
|
@ -23,6 +24,28 @@ class Misc {
|
|||
],
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('say', [__CLASS__, 'say'], [
|
||||
'description' => 'says stuff back to you',
|
||||
'usage' => '<stuff to say>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
self::$bot->registerCommand('dm', [__CLASS__, 'dm'], [
|
||||
'description' => 'sends a dm',
|
||||
'usage' => '<@user> <message>',
|
||||
'registerHelp' => true,
|
||||
'aliases' => [
|
||||
'pm',
|
||||
],
|
||||
]);
|
||||
self::$bot->registerCommand('avatar', [__CLASS__, 'avatar'], [
|
||||
'description' => 'gets avatar for a user (gets your own if you don\'t mention anyone)',
|
||||
'usage' => '<@user>',
|
||||
'aliases' => [
|
||||
'profilepic',
|
||||
'pic',
|
||||
'userpic',
|
||||
],
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
@ -58,4 +81,62 @@ class Misc {
|
|||
return "message sent to benh";
|
||||
}
|
||||
}
|
||||
|
||||
public static function say($msg, $args)
|
||||
{
|
||||
$a = s(implode(" ", $args));
|
||||
if ($a->contains("@everyone") || $a->contains("@here")) {
|
||||
return "sorry can't do that! :P";
|
||||
}
|
||||
Utils::send($msg, "$a\n\n**love**, {$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
public static function sing($msg, $args)
|
||||
{
|
||||
$a = s(implode(" ", $args));
|
||||
if ($a->contains("@everyone") || $a->contains("@here")) {
|
||||
return "sorry can't do that! :P";
|
||||
}
|
||||
Utils::send($msg, ":musical_note::musical_note::musical_note::musical_note::musical_note::musical_note:\n\n$a\n\n:musical_note::musical_note::musical_note::musical_note::musical_note::musical_note:, {$msg->author}")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
});
|
||||
}
|
||||
|
||||
public static function dm($msg, $args)
|
||||
{
|
||||
if (Utils::isDM($msg)) {
|
||||
return "you're already in a DM, silly";
|
||||
}
|
||||
if (count($msg->mentions) == 0) {
|
||||
$msg->author->user->sendMessage("hi, {$msg->author} said:\n" . implode(" ", $args));
|
||||
} else {
|
||||
foreach ($msg->mentions as $mention) {
|
||||
$mention->sendMessage("hi!\n{$msg->author} said:\n\n" . implode(" ", $args));
|
||||
}
|
||||
}
|
||||
Utils::send($msg, "sent!")->then(function ($result) use ($msg) {
|
||||
Utils::deleteMessage($msg);
|
||||
self::$bot->loop->addTimer(3, function ($timer) use ($msg, $result) {
|
||||
Utils::deleteMessage($result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static function avatar($msg, $args)
|
||||
{
|
||||
if (count($msg->mentions) === 0) {
|
||||
if (Utils::isDM($msg)) {
|
||||
Utils::send($msg, $msg->author->avatar);
|
||||
} else {
|
||||
Utils::send($msg, $msg->author->user->avatar);
|
||||
}
|
||||
} else {
|
||||
foreach ($msg->mentions as $mention) {
|
||||
Utils::send($msg, $mention->avatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
use BenBot\Cities;
|
||||
|
||||
class Time {
|
||||
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,9 @@
|
|||
namespace BenBot\Commands;
|
||||
error_reporting(-1);
|
||||
|
||||
use BenBot\Utils;
|
||||
use BenBot\Cities;
|
||||
|
||||
class Weather {
|
||||
|
||||
private static $bot;
|
||||
|
@ -11,13 +14,75 @@ class Weather {
|
|||
self::$bot = $that;
|
||||
|
||||
$weather = self::$bot->registerCommand('weather', [__CLASS__, 'weather'], [
|
||||
'description' => 'just some greetings'
|
||||
'description' => 'get current weather',
|
||||
'usage' => '<@user | city, country>',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
$weather->registerSubCommand('save', "BenBot\Commands\Cities::saveCity", [
|
||||
'description' => 'saves a city for a user to look up weather and current time',
|
||||
]);
|
||||
|
||||
echo __CLASS__ . " registered", PHP_EOL;
|
||||
}
|
||||
|
||||
public static function weather($msg, $args)
|
||||
{
|
||||
return "WIP";
|
||||
}
|
||||
|
||||
|
||||
public static function celsiusToFahrenheit($celsius)
|
||||
{
|
||||
return $celsius * 9 / 5 + 32;
|
||||
}
|
||||
|
||||
public static function fahrenheitToCelsius($fahrenheit)
|
||||
{
|
||||
return $fahrenheit * 5 / 9 + 32;
|
||||
}
|
||||
|
||||
public static function formatWeatherJson($json, $timezone = null)
|
||||
{
|
||||
|
||||
return self::$bot->factory(Embed::class, [
|
||||
'title' => "Weather in {$json->name}, {$json->sys->country}",
|
||||
'thumbnail' => ['url' => "http://openweathermap.org/img/w/{$json->weather[0]->icon}.png"],
|
||||
'fields' => [
|
||||
['name' => 'Current temperature'
|
||||
, 'value' => "{$json->main->temp}°C (".self::celsiusToFahrenheit($json->main->temp)."°F)"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Low/High Forecasted Temp'
|
||||
, 'value' => "{$json->main->temp_min}/{$json->main->temp_max}°C " . self::celsiusToFahrenheit($json->main->temp_min) . "/" . self::celsiusToFahrenheit($json->main->temp_max) . "°F"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Current conditions'
|
||||
, 'value' => $json->weather[0]->description
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Atmospheric Pressure'
|
||||
, 'value' => "{$json->main->pressure} hPa"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Humidity'
|
||||
, 'value' => "{$json->main->humidity} %"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Wind'
|
||||
, 'value' => "{$json->wind->speed} meters/second, {$json->wind->deg}°"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Sunrise'
|
||||
, 'value' => Carbon::createFromTimestamp($json->sys->sunrise, $timezone)->toTimeString()
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Sunset'
|
||||
, 'value' => Carbon::createFromTimestamp($json->sys->sunset, $timezone)->toTimeString()
|
||||
, 'inline' => true
|
||||
],
|
||||
],
|
||||
'timestamp' => null,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,32 +7,11 @@ use function Stringy\create as s;
|
|||
|
||||
class FontConverter {
|
||||
|
||||
public static function blockText($text) {
|
||||
$ret = "";
|
||||
foreach (s($text)->toLowerCase() as $char) {
|
||||
if (ctype_alpha($char)) $ret .= ":regional_indicator_" . $char . ": ";
|
||||
else if (ctype_digit($char)) {
|
||||
switch ($char) {
|
||||
case 0: $ret .= ":zero: "; break;
|
||||
case 1: $ret .= ":one: "; break;
|
||||
case 2: $ret .= ":two: "; break;
|
||||
case 3: $ret .= ":three: "; break;
|
||||
case 4: $ret .= ":four: "; break;
|
||||
case 5: $ret .= ":five: "; break;
|
||||
case 6: $ret .= ":six: "; break;
|
||||
case 7: $ret .= ":seven: "; break;
|
||||
case 8: $ret .= ":eight: "; break;
|
||||
case 9: $ret .= ":nine: "; break;
|
||||
}
|
||||
}
|
||||
else if ($char == " ") $ret .= " ";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public static $fonts;
|
||||
|
||||
public static function __callStatic($name, $args)
|
||||
public static function init()
|
||||
{
|
||||
$fonts = [
|
||||
self::$fonts = [
|
||||
'full' => [
|
||||
'lowers' => s('abcdefghijklmnopqrstuvwxyz'),
|
||||
'uppers' => s('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
|
||||
|
@ -79,9 +58,37 @@ class FontConverter {
|
|||
'nums' => s('0123456789'),
|
||||
],
|
||||
];
|
||||
if (!isset($fonts[$name])) {
|
||||
}
|
||||
|
||||
public static function blockText($text) {
|
||||
$ret = "";
|
||||
foreach (s($text)->toLowerCase() as $char) {
|
||||
if (ctype_alpha($char)) $ret .= ":regional_indicator_" . $char . ": ";
|
||||
else if (ctype_digit($char)) {
|
||||
switch ($char) {
|
||||
case 0: $ret .= ":zero: "; break;
|
||||
case 1: $ret .= ":one: "; break;
|
||||
case 2: $ret .= ":two: "; break;
|
||||
case 3: $ret .= ":three: "; break;
|
||||
case 4: $ret .= ":four: "; break;
|
||||
case 5: $ret .= ":five: "; break;
|
||||
case 6: $ret .= ":six: "; break;
|
||||
case 7: $ret .= ":seven: "; break;
|
||||
case 8: $ret .= ":eight: "; break;
|
||||
case 9: $ret .= ":nine: "; break;
|
||||
}
|
||||
}
|
||||
else if ($char == " ") $ret .= " ";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
|
||||
if (!isset(self::$fonts[$name])) {
|
||||
$ret = "sorry that font doesn't exist. try these fonts:\n";
|
||||
$ret .= implode(", ", array_keys($fonts));
|
||||
$ret .= implode(", ", array_keys(self::$fonts));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -89,11 +96,11 @@ class FontConverter {
|
|||
foreach (s($args[0]) as $char) {
|
||||
$ord = ord($char);
|
||||
if ($ord >= ord('0') && $ord <= ord('9')) {
|
||||
$ret .= $fonts[$name]["nums"][$ord - ord('0')];
|
||||
$ret .= self::$fonts[$name]["nums"][$ord - ord('0')];
|
||||
} elseif ($ord >= ord('a') && $ord <= ord('z')) {
|
||||
$ret .= $fonts[$name]["lowers"][$ord - ord('a')];
|
||||
$ret .= self::$fonts[$name]["lowers"][$ord - ord('a')];
|
||||
} elseif ($ord >= ord('A') && $ord <= ord('Z')) {
|
||||
$ret .= $fonts[$name]["uppers"][$ord - ord('A')];
|
||||
$ret .= self::$fonts[$name]["uppers"][$ord - ord('A')];
|
||||
} elseif ($char == " ") {
|
||||
$ret .= " ";
|
||||
} else {
|
||||
|
|
135
src/Utils.php
135
src/Utils.php
|
@ -13,7 +13,7 @@ class Utils {
|
|||
public static function init(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
echo "Utils initialized.", PHP_EOL;
|
||||
echo PHP_EOL, "Utils initialized.", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ class Utils {
|
|||
return $msg->channel->sendMessage($txt, false, $embed)
|
||||
->otherwise(function($e) use ($msg) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
echo $e->getTraceAsString(), PHP_EOL;
|
||||
$msg->reply("sry, an error occurred. check with <@193011352275648514>.\n```{$e->getMessage()}```");
|
||||
self::ping($e->getMessage());
|
||||
});
|
||||
|
@ -34,6 +35,7 @@ class Utils {
|
|||
return $msg->channel->sendFile($filepath, $filename, $txt)
|
||||
->otherwise(function($e) use ($msg) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
echo $e->getTraceAsString(), PHP_EOL;
|
||||
$msg->reply("sry, an error occurred. check with <@193011352275648514>.\n```{$e->getMessage()}```");
|
||||
self::ping($e->getMessage());
|
||||
});
|
||||
|
@ -46,86 +48,18 @@ class Utils {
|
|||
}
|
||||
|
||||
|
||||
public static function getUserIDFromMsg($msg)
|
||||
{
|
||||
return self::isDM($msg) ? $msg->author->id : $msg->author->user->id;
|
||||
}
|
||||
|
||||
|
||||
public static function timestampFromSnowflake ($snowflake)
|
||||
{
|
||||
return (($snowflake / 4194304) + 1420070400000) / 1000;
|
||||
}
|
||||
|
||||
|
||||
public static function celsiusToFahrenheit($celsius)
|
||||
{
|
||||
return $celsius * 9 / 5 + 32;
|
||||
}
|
||||
|
||||
public static function fahrenheitToCelsius($fahrenheit)
|
||||
{
|
||||
return $fahrenheit * 5 / 9 + 32;
|
||||
}
|
||||
|
||||
public static function formatWeatherJson($json, $timezone = null)
|
||||
{
|
||||
|
||||
return self::$bot->factory(Embed::class, [
|
||||
'title' => "Weather in {$json->name}, {$json->sys->country}",
|
||||
'thumbnail' => ['url' => "http://openweathermap.org/img/w/{$json->weather[0]->icon}.png"],
|
||||
'fields' => [
|
||||
['name' => 'Current temperature'
|
||||
, 'value' => "{$json->main->temp}°C (".self::celsiusToFahrenheit($json->main->temp)."°F)"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Low/High Forecasted Temp'
|
||||
, 'value' => "{$json->main->temp_min}/{$json->main->temp_max}°C " . self::celsiusToFahrenheit($json->main->temp_min) . "/" . self::celsiusToFahrenheit($json->main->temp_max) . "°F"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Current conditions'
|
||||
, 'value' => $json->weather[0]->description
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Atmospheric Pressure'
|
||||
, 'value' => "{$json->main->pressure} hPa"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Humidity'
|
||||
, 'value' => "{$json->main->humidity} %"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Wind'
|
||||
, 'value' => "{$json->wind->speed} meters/second, {$json->wind->deg}°"
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Sunrise'
|
||||
, 'value' => Carbon::createFromTimestamp($json->sys->sunrise, $timezone)->toTimeString()
|
||||
, 'inline' => true
|
||||
],
|
||||
['name' => 'Sunset'
|
||||
, 'value' => Carbon::createFromTimestamp($json->sys->sunset, $timezone)->toTimeString()
|
||||
, 'inline' => true
|
||||
],
|
||||
],
|
||||
'timestamp' => null,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function askCleverbot($input)
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$url = "https://www.cleverbot.com/getreply";
|
||||
$key = getenv('CLEVERBOT_API_KEY');
|
||||
$input = rawurlencode($input);
|
||||
self::$bot->discord->http->get("$url?input=$input&key=$key", null, [], false)->then(function ($apidata) use ($deferred) {
|
||||
$deferred->resolve($apidata);
|
||||
}, function ($e) {
|
||||
$deferred->reject($e);
|
||||
});
|
||||
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
|
||||
public static function ping($msg)
|
||||
{
|
||||
if (is_null(self::$bot)) {
|
||||
|
@ -137,6 +71,7 @@ class Utils {
|
|||
->sendMessage("<@193011352275648514>, $msg");
|
||||
}
|
||||
|
||||
|
||||
public static function secondsConvert($uptime)
|
||||
{
|
||||
// Method here heavily based on freebsd's uptime source
|
||||
|
@ -152,23 +87,38 @@ class Utils {
|
|||
// Send out formatted string
|
||||
$return = array();
|
||||
if ($years > 0) {
|
||||
$return[] = $years.' '.($years > 1 ? self::$lang['years'] : substr(self::$lang['years'], 0, strlen(self::$lang['years']) - 1));
|
||||
$return[] = $years.' '.($years > 1 ? 'years' : 'year');
|
||||
}
|
||||
if ($days > 0) {
|
||||
$return[] = $days.' '.self::$lang['days'];
|
||||
$return[] = $days.' days';
|
||||
}
|
||||
if ($hours > 0) {
|
||||
$return[] = $hours.' '.self::$lang['hours'];
|
||||
$return[] = $hours.' hours';
|
||||
}
|
||||
if ($minutes > 0) {
|
||||
$return[] = $minutes.' '.self::$lang['minutes'];
|
||||
$return[] = $minutes.' minutes';
|
||||
}
|
||||
if ($seconds > 0) {
|
||||
$return[] = $seconds.(date('m/d') == '06/03' ? ' sex' : ' '.self::$lang['seconds']);
|
||||
$return[] = $seconds.(date('m/d') == '06/03' ? ' sex' : ' seconds');
|
||||
}
|
||||
return implode(', ', $return);
|
||||
}
|
||||
|
||||
|
||||
public static function convertMemoryUsage($system = false)
|
||||
{
|
||||
$mem_usage = memory_get_usage($system);
|
||||
|
||||
if ($mem_usage < 1024) {
|
||||
return "$mem_usage bytes";
|
||||
} elseif ($mem_usage < 1048576) {
|
||||
return round($mem_usage / 1024, 2) . " kilobytes";
|
||||
} else {
|
||||
return round($mem_usage / 1048576, 2) . " megabytes";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function deleteMessage($msg)
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
@ -185,10 +135,12 @@ class Utils {
|
|||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function editMessage($msg, $text)
|
||||
|
||||
public static function editMessage($msg, $text)
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
$this->discord->http->patch(
|
||||
|
||||
self::$bot->http->patch(
|
||||
"channels/{$msg->channel->id}/messages/{$msg->id}",
|
||||
[
|
||||
'content' => $text
|
||||
|
@ -198,9 +150,26 @@ class Utils {
|
|||
$msg->fill($response);
|
||||
$deferred->resolve($msg);
|
||||
},
|
||||
\React\Partial\bind_right($msg->reject, $deferred)
|
||||
\React\Partial\bind_right($this->reject, $deferred)
|
||||
);
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
|
||||
public static function arrayFlatten($array)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
$result = [];
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$result = array_merge($result, self::arrayFlatten($val));
|
||||
} else {
|
||||
$result[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue