Created
September 11, 2018 15:58
-
-
Save Animeshz/565cea0fd23273a5f63517563cbf866a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ClusterPlus | |
* Copyright 2018 Animeshz, All Rights Reserved | |
* | |
* License: https://github.com/Animeshz/ClusterPlus/blob/master/LICENSE | |
*/ | |
return function(\CharlotteDunois\Yasmin\Client $client) { | |
return (new class($client) extends \CharlotteDunois\Livia\Commands\Command { | |
function __construct($client) { | |
parent::__construct($client, array( | |
'name' => 'avatar', | |
'group' => 'clusterplus_meta', | |
'description' => 'Shows the avatar of the user if not found nothing is sent', | |
'guildOnly' => true, | |
'args' => array( | |
array( | |
'key' => 'user', | |
'prompt' => 'user', | |
'type' => 'users', | |
'default' => '' | |
) | |
) | |
)); | |
} | |
function run(\CharlotteDunois\Livia\CommandMessage $message, \ArrayObject $args, bool $fromPattern) | |
{ | |
$embed = new \CharlotteDunois\Yasmin\Models\MessageEmbed(['color'=> '3447003']); | |
if($args['user'] !== '') { | |
$av = $args['user']->getAvatarURL(); | |
$message->channel->send('', ['embed' => $embed]); | |
} else { | |
$av = $message->message->author->getAvatarURL(); | |
} | |
if($av !== null) { | |
$embed->setImage($av); | |
} else { | |
$embed->setDescription('Image not found'); | |
} | |
$message->message->channel->send('', ['embed' => $embed]); | |
$message->reply('hey'); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ClusterPlus | |
* Copyright 2018 Animeshz, All Rights Reserved | |
* | |
* License: https://github.com/Animeshz/ClusterPlus/blob/master/LICENSE | |
*/ | |
namespace ClusterPlus\Commands\types; | |
class CustomUserArgumentType extends \CharlotteDunois\Livia\Types\ArgumentType { | |
function __construct(\CharlotteDunois\Livia\LiviaClient $client) | |
{ | |
parent::__construct($client, 'users'); | |
} | |
function validate(string $value, \CharlotteDunois\Livia\CommandMessage $message, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) { | |
$prg = \preg_match('/(?:<@!?)?(\d{15,})>?/', $value, $matches); | |
if($prg === 1) { | |
return $message->client->fetchUser($matches[1])->then(function () { | |
return true; | |
}, function () { | |
return false; | |
}); | |
} | |
$search = \mb_strtolower($value); | |
$inexactUsers = $this->client->users->filter(function ($user) use ($search) { | |
return (\mb_stripos($user->tag, $search) !== false); | |
}); | |
$inexactLength = $inexactUsers->count(); | |
if($inexactLength === 0) { | |
return false; | |
} | |
if($inexactLength === 1) { | |
return true; | |
} | |
$exactUsers = $this->client->users->filter(function ($user) use ($search) { | |
return (\mb_strtolower($user->tag) === $search); | |
}); | |
$exactLength = $exactUsers->count(); | |
if($exactLength === 1) { | |
return true; | |
} | |
if($exactLength > 0) { | |
$users = $exactUsers; | |
} else { | |
$users = $inexactUsers; | |
} | |
if($users->count() >= 15) { | |
return 'Multiple users found. Please be more specific.'; | |
} | |
$users = $users->map(function (\CharlotteDunois\Yasmin\Models\User $user) { | |
return $user->tag; | |
}); | |
return \CharlotteDunois\Livia\Utils\DataHelpers::disambiguation($users, 'users', null).\PHP_EOL; | |
} | |
function parse(string $value, \CharlotteDunois\Livia\CommandMessage $message, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) { | |
$prg = \preg_match('/(?:<@!?)?(\d{15,})>?/', $value, $matches); | |
if($prg === 1) { | |
return $this->client->users->get($matches[1]); | |
} | |
$search = \mb_strtolower($value); | |
$inexactUsers = $this->client->users->filter(function ($user) use ($search) { | |
return (\mb_stripos($user->tag, $search) !== false); | |
}); | |
$inexactLength = $inexactUsers->count(); | |
if($inexactLength === 0) { | |
return null; | |
} | |
if($inexactLength === 1) { | |
return $inexactUsers->first(); | |
} | |
$exactUsers = $this->client->users->filter(function ($user) use ($search) { | |
return (\mb_strtolower($user->tag) === $search); | |
}); | |
$exactLength = $exactUsers->count(); | |
if($exactLength === 1) { | |
return $exactUsers->first(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment