repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
CharlotteDunois/Yasmin | src/Traits/GuildChannelTrait.php | GuildChannelTrait.overwritesFor | function overwritesFor($member) {
$member = $this->guild->members->resolve($member);
$everyoneOverwrites = null;
$memberOverwrites = null;
$rolesOverwrites = array();
foreach($this->permissionOverwrites as $overwrite) {
if($overwrite->id === $this->guild->id) {
$everyoneOverwrites = $overwrite;
} elseif($overwrite->id === $member->id) {
$memberOverwrites = $overwrite;
} elseif($member->roles->has($overwrite->id)) {
$rolesOverwrites[] = $overwrite;
}
}
return array(
'everyone' => $everyoneOverwrites,
'member' => $memberOverwrites,
'roles' => $rolesOverwrites
);
} | php | function overwritesFor($member) {
$member = $this->guild->members->resolve($member);
$everyoneOverwrites = null;
$memberOverwrites = null;
$rolesOverwrites = array();
foreach($this->permissionOverwrites as $overwrite) {
if($overwrite->id === $this->guild->id) {
$everyoneOverwrites = $overwrite;
} elseif($overwrite->id === $member->id) {
$memberOverwrites = $overwrite;
} elseif($member->roles->has($overwrite->id)) {
$rolesOverwrites[] = $overwrite;
}
}
return array(
'everyone' => $everyoneOverwrites,
'member' => $memberOverwrites,
'roles' => $rolesOverwrites
);
} | [
"function",
"overwritesFor",
"(",
"$",
"member",
")",
"{",
"$",
"member",
"=",
"$",
"this",
"->",
"guild",
"->",
"members",
"->",
"resolve",
"(",
"$",
"member",
")",
";",
"$",
"everyoneOverwrites",
"=",
"null",
";",
"$",
"memberOverwrites",
"=",
"null",
... | Returns the permissions overwrites for the given member as an associative array.
```
array(
'everyone' => \CharlotteDunois\Yasmin\Models\PermissionOverwrite|null,
'member' => \CharlotteDunois\Yasmin\Models\PermissionOverwrite|null,
'roles' => \CharlotteDunois\Yasmin\Models\PermissionOverwrite[]
)
```
@param \CharlotteDunois\Yasmin\Models\GuildMember|string $member
@return array
@throws \InvalidArgumentException | [
"Returns",
"the",
"permissions",
"overwrites",
"for",
"the",
"given",
"member",
"as",
"an",
"associative",
"array",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/GuildChannelTrait.php#L261-L283 |
CharlotteDunois/Yasmin | src/Traits/GuildChannelTrait.php | GuildChannelTrait.overwritePermissions | function overwritePermissions($memberOrRole, $allow, $deny = 0, string $reason = '') {
[ $memberOrRole, $options ] = $this->validateOverwritePermissions($memberOrRole, $allow, $deny);
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($memberOrRole, $options, $reason) {
$this->client->apimanager()->endpoints->channel->editChannelPermissions($this->id, $memberOrRole, $options, $reason)->done(function () use ($memberOrRole, $options, $resolve, $reject) {
$options['id'] = $memberOrRole;
if($options['type'] === 'member') {
$fetch = $this->guild->fetchMember($options['id']);
} else {
$fetch = \React\Promise\resolve();
}
$fetch->done(function () use ($options, $resolve) {
if($options['allow'] instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$options['allow'] = $options['allow']->bitfield;
}
if($options['deny'] instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$options['deny'] = $options['deny']->bitfield;
}
$overwrite = new \CharlotteDunois\Yasmin\Models\PermissionOverwrite($this->client, $this, $options);
$this->permissionOverwrites->set($overwrite->id, $overwrite);
$resolve($overwrite);
}, $reject);
}, $reject);
}));
} | php | function overwritePermissions($memberOrRole, $allow, $deny = 0, string $reason = '') {
[ $memberOrRole, $options ] = $this->validateOverwritePermissions($memberOrRole, $allow, $deny);
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($memberOrRole, $options, $reason) {
$this->client->apimanager()->endpoints->channel->editChannelPermissions($this->id, $memberOrRole, $options, $reason)->done(function () use ($memberOrRole, $options, $resolve, $reject) {
$options['id'] = $memberOrRole;
if($options['type'] === 'member') {
$fetch = $this->guild->fetchMember($options['id']);
} else {
$fetch = \React\Promise\resolve();
}
$fetch->done(function () use ($options, $resolve) {
if($options['allow'] instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$options['allow'] = $options['allow']->bitfield;
}
if($options['deny'] instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$options['deny'] = $options['deny']->bitfield;
}
$overwrite = new \CharlotteDunois\Yasmin\Models\PermissionOverwrite($this->client, $this, $options);
$this->permissionOverwrites->set($overwrite->id, $overwrite);
$resolve($overwrite);
}, $reject);
}, $reject);
}));
} | [
"function",
"overwritePermissions",
"(",
"$",
"memberOrRole",
",",
"$",
"allow",
",",
"$",
"deny",
"=",
"0",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"[",
"$",
"memberOrRole",
",",
"$",
"options",
"]",
"=",
"$",
"this",
"->",
"validateOverwri... | Overwrites the permissions for a member or role in this channel. Resolves with an instance of PermissionOverwrite.
@param \CharlotteDunois\Yasmin\Models\GuildMember|\CharlotteDunois\Yasmin\Models\Role|string $memberOrRole The member or role.
@param \CharlotteDunois\Yasmin\Models\Permissions|int $allow Which permissions should be allowed?
@param \CharlotteDunois\Yasmin\Models\Permissions|int $deny Which permissions should be denied?
@param string $reason The reason for this.
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException
@see \CharlotteDunois\Yasmin\Models\PermissionOverwrite | [
"Overwrites",
"the",
"permissions",
"for",
"a",
"member",
"or",
"role",
"in",
"this",
"channel",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"PermissionOverwrite",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/GuildChannelTrait.php#L295-L324 |
CharlotteDunois/Yasmin | src/Traits/GuildChannelTrait.php | GuildChannelTrait.lockPermissions | function lockPermissions(string $reason = '') {
if(!$this->parent) {
throw new \BadMethodCallException('This channel does not have a parent');
}
$overwrites = \array_values($this->parent->permissionOverwrites->map(function ($overwrite) {
return array(
'id' => $overwrite->id,
'type' => $overwrite->type,
'allow' => $overwrite->allow->bitfield,
'deny' => $overwrite->deny->bitfield
);
})->all());
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($overwrites, $reason) {
$promises = array();
$overwritesID = \array_column($overwrites, 'id');
foreach($this->permissionOverwrites as $perm) {
if(!\in_array($perm->id, $overwritesID)) {
$promises[] = $perm->delete($reason);
}
}
foreach($overwrites as $overwrite) {
$promises[] = $this->client->apimanager()->endpoints->channel->editChannelPermissions($this->id, $overwrite['id'], $overwrite, $reason);
}
\React\Promise\all($promises)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function lockPermissions(string $reason = '') {
if(!$this->parent) {
throw new \BadMethodCallException('This channel does not have a parent');
}
$overwrites = \array_values($this->parent->permissionOverwrites->map(function ($overwrite) {
return array(
'id' => $overwrite->id,
'type' => $overwrite->type,
'allow' => $overwrite->allow->bitfield,
'deny' => $overwrite->deny->bitfield
);
})->all());
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($overwrites, $reason) {
$promises = array();
$overwritesID = \array_column($overwrites, 'id');
foreach($this->permissionOverwrites as $perm) {
if(!\in_array($perm->id, $overwritesID)) {
$promises[] = $perm->delete($reason);
}
}
foreach($overwrites as $overwrite) {
$promises[] = $this->client->apimanager()->endpoints->channel->editChannelPermissions($this->id, $overwrite['id'], $overwrite, $reason);
}
\React\Promise\all($promises)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"lockPermissions",
"(",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parent",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'This channel does not have a parent'",
")",
";",
"}",
"$",
"overwr... | Locks in the permission overwrites from the parent channel. Resolves with $this.
@param string $reason The reason for this.
@return \React\Promise\ExtendedPromiseInterface
@throws \BadMethodCallException | [
"Locks",
"in",
"the",
"permission",
"overwrites",
"from",
"the",
"parent",
"channel",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/GuildChannelTrait.php#L332-L364 |
CharlotteDunois/Yasmin | src/Traits/GuildChannelTrait.php | GuildChannelTrait.setPosition | function setPosition(int $position, string $reason = '') {
if($position < 0) {
throw new \InvalidArgumentException('Position can not be below 0');
}
$newPositions = array();
$newPositions[] = array('id' => $this->id, 'position' => $position);
$count = $this->guild->channels->count();
$channels = $this->guild->channels->sortCustom(function ($a, $b) {
if($a->position === $b->position) {
return $a->id <=> $b->id;
}
return $a->position <=> $b->position;
})->values()->all();
$pos = 0;
for($i = 0; $i < $count; $i++) {
if($pos === $position) {
$pos++;
}
$channel = $channels[$i];
if($pos === $channel->position) {
continue;
}
$newPositions[] = array('id' => $channel, 'position' => $pos);
$pos++;
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($newPositions, $reason) {
$this->client->apimanager()->endpoints->guild->modifyGuildChannelPositions($this->guild->id, $newPositions, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function setPosition(int $position, string $reason = '') {
if($position < 0) {
throw new \InvalidArgumentException('Position can not be below 0');
}
$newPositions = array();
$newPositions[] = array('id' => $this->id, 'position' => $position);
$count = $this->guild->channels->count();
$channels = $this->guild->channels->sortCustom(function ($a, $b) {
if($a->position === $b->position) {
return $a->id <=> $b->id;
}
return $a->position <=> $b->position;
})->values()->all();
$pos = 0;
for($i = 0; $i < $count; $i++) {
if($pos === $position) {
$pos++;
}
$channel = $channels[$i];
if($pos === $channel->position) {
continue;
}
$newPositions[] = array('id' => $channel, 'position' => $pos);
$pos++;
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($newPositions, $reason) {
$this->client->apimanager()->endpoints->guild->modifyGuildChannelPositions($this->guild->id, $newPositions, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"setPosition",
"(",
"int",
"$",
"position",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"position",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Position can not be below 0'",
")",
";",
"}"... | Sets the position of the channel. Resolves with $this.
@param int $position
@param string $reason
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException | [
"Sets",
"the",
"position",
"of",
"the",
"channel",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/GuildChannelTrait.php#L417-L455 |
CharlotteDunois/Yasmin | src/Traits/GuildChannelTrait.php | GuildChannelTrait.validateOverwritePermissions | protected function validateOverwritePermissions($memberOrRole, $allow, $deny = 0) {
$options = array();
if($memberOrRole instanceof \CharlotteDunois\Yasmin\Models\GuildMember) {
$memberOrRole = $memberOrRole->id;
$options['type'] = 'member';
} elseif($memberOrRole instanceof \CharlotteDunois\Yasmin\Models\Role) {
$memberOrRole = $memberOrRole->id;
$options['type'] = 'role';
} else {
try {
$memberOrRole = $this->guild->roles->resolve($memberOrRole)->id;
$options['type'] = 'role';
} catch (\InvalidArgumentException $e) {
$options['type'] = 'member';
}
}
if(!\is_int($allow) && !($allow instanceof \CharlotteDunois\Yasmin\Models\Permissions)) {
throw new \InvalidArgumentException('Allow has to be an int or an instance of Permissions');
}
if(!\is_int($deny) && !($deny instanceof \CharlotteDunois\Yasmin\Models\Permissions)) {
throw new \InvalidArgumentException('Deny has to be an int or an instance of Permissions');
}
if(\json_encode($allow) === \json_encode($deny)) {
throw new \InvalidArgumentException('Allow and deny must have different permissions');
}
$options['allow'] = $allow;
$options['deny'] = $deny;
return array($memberOrRole, $options);
} | php | protected function validateOverwritePermissions($memberOrRole, $allow, $deny = 0) {
$options = array();
if($memberOrRole instanceof \CharlotteDunois\Yasmin\Models\GuildMember) {
$memberOrRole = $memberOrRole->id;
$options['type'] = 'member';
} elseif($memberOrRole instanceof \CharlotteDunois\Yasmin\Models\Role) {
$memberOrRole = $memberOrRole->id;
$options['type'] = 'role';
} else {
try {
$memberOrRole = $this->guild->roles->resolve($memberOrRole)->id;
$options['type'] = 'role';
} catch (\InvalidArgumentException $e) {
$options['type'] = 'member';
}
}
if(!\is_int($allow) && !($allow instanceof \CharlotteDunois\Yasmin\Models\Permissions)) {
throw new \InvalidArgumentException('Allow has to be an int or an instance of Permissions');
}
if(!\is_int($deny) && !($deny instanceof \CharlotteDunois\Yasmin\Models\Permissions)) {
throw new \InvalidArgumentException('Deny has to be an int or an instance of Permissions');
}
if(\json_encode($allow) === \json_encode($deny)) {
throw new \InvalidArgumentException('Allow and deny must have different permissions');
}
$options['allow'] = $allow;
$options['deny'] = $deny;
return array($memberOrRole, $options);
} | [
"protected",
"function",
"validateOverwritePermissions",
"(",
"$",
"memberOrRole",
",",
"$",
"allow",
",",
"$",
"deny",
"=",
"0",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"memberOrRole",
"instanceof",
"\\",
"CharlotteDunois",
... | Validates the given overwritePermissions arguments.
@param \CharlotteDunois\Yasmin\Models\GuildMember|\CharlotteDunois\Yasmin\Models\Role|string $memberOrRole The member or role.
@param \CharlotteDunois\Yasmin\Models\Permissions|int $allow Which permissions should be allowed?
@param \CharlotteDunois\Yasmin\Models\Permissions|int $deny Which permissions should be denied?
@return array
@throws \InvalidArgumentException | [
"Validates",
"the",
"given",
"overwritePermissions",
"arguments",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/GuildChannelTrait.php#L476-L510 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Json.php | Json.decode | function decode(string $data) {
$msg = \json_decode($data, true);
if($msg === null && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The JSON decoder was unable to decode the data. Error: '.\json_last_error_msg());
}
return $msg;
} | php | function decode(string $data) {
$msg = \json_decode($data, true);
if($msg === null && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The JSON decoder was unable to decode the data. Error: '.\json_last_error_msg());
}
return $msg;
} | [
"function",
"decode",
"(",
"string",
"$",
"data",
")",
"{",
"$",
"msg",
"=",
"\\",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"$",
"msg",
"===",
"null",
"&&",
"\\",
"json_last_error",
"(",
")",
"!==",
"\\",
"JSON_ERROR_NONE",
... | Decodes data.
@param string $data
@return mixed
@throws \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException | [
"Decodes",
"data",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Json.php#L40-L47 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Json.php | Json.encode | function encode($data): string {
$msg = \json_encode($data);
if($msg === false && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The JSON encoder was unable to encode the data. Error: '.\json_last_error_msg());
}
return $msg;
} | php | function encode($data): string {
$msg = \json_encode($data);
if($msg === false && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The JSON encoder was unable to encode the data. Error: '.\json_last_error_msg());
}
return $msg;
} | [
"function",
"encode",
"(",
"$",
"data",
")",
":",
"string",
"{",
"$",
"msg",
"=",
"\\",
"json_encode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"msg",
"===",
"false",
"&&",
"\\",
"json_last_error",
"(",
")",
"!==",
"\\",
"JSON_ERROR_NONE",
")",
... | Encodes data.
@param mixed $data
@return string
@throws \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException | [
"Encodes",
"data",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Json.php#L55-L62 |
CharlotteDunois/Yasmin | src/Models/CategoryChannel.php | CategoryChannel.getChildren | function getChildren() {
return $this->guild->channels->filter(function ($channel) {
return ($channel->parentID === $this->id);
});
} | php | function getChildren() {
return $this->guild->channels->filter(function ($channel) {
return ($channel->parentID === $this->id);
});
} | [
"function",
"getChildren",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"guild",
"->",
"channels",
"->",
"filter",
"(",
"function",
"(",
"$",
"channel",
")",
"{",
"return",
"(",
"$",
"channel",
"->",
"parentID",
"===",
"$",
"this",
"->",
"id",
")",
";... | Returns all channels which are childrens of this category.
@return \CharlotteDunois\Yasmin\Interfaces\StorageInterface | [
"Returns",
"all",
"channels",
"which",
"are",
"childrens",
"of",
"this",
"category",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/CategoryChannel.php#L101-L105 |
CharlotteDunois/Yasmin | src/Models/Webhook.php | Webhook.edit | function edit(array $options, string $reason = '') {
$data = array();
if(!empty($options['name'])) {
$data['name'] = $options['name'];
}
if(!empty($options['channel'])) {
$data['channel'] = $this->client->channels->resolve($options['channel'])->getId();
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($data, $options, $reason) {
\CharlotteDunois\Yasmin\Utils\FileHelpers::resolveFileResolvable(($options['avatar'] ?? ''))->done(function ($avatar = null) use ($data, $reason, $resolve, $reject) {
if(!empty($avatar)) {
$data['avatar'] = \CharlotteDunois\Yasmin\Utils\DataHelpers::makeBase64URI($avatar);
}
$method = 'modifyWebhook';
$args = array($this->id, $data, $reason);
if(!empty($this->token)) {
$method = 'modifyWebhookToken';
$args = array($this->id, $this->token, $data, $reason);
}
$this->client->apimanager()->endpoints->webhook->$method(...$args)->done(function ($data) use ($resolve) {
$this->_patch($data);
$resolve($this);
}, $reject);
}, $reject);
}));
} | php | function edit(array $options, string $reason = '') {
$data = array();
if(!empty($options['name'])) {
$data['name'] = $options['name'];
}
if(!empty($options['channel'])) {
$data['channel'] = $this->client->channels->resolve($options['channel'])->getId();
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($data, $options, $reason) {
\CharlotteDunois\Yasmin\Utils\FileHelpers::resolveFileResolvable(($options['avatar'] ?? ''))->done(function ($avatar = null) use ($data, $reason, $resolve, $reject) {
if(!empty($avatar)) {
$data['avatar'] = \CharlotteDunois\Yasmin\Utils\DataHelpers::makeBase64URI($avatar);
}
$method = 'modifyWebhook';
$args = array($this->id, $data, $reason);
if(!empty($this->token)) {
$method = 'modifyWebhookToken';
$args = array($this->id, $this->token, $data, $reason);
}
$this->client->apimanager()->endpoints->webhook->$method(...$args)->done(function ($data) use ($resolve) {
$this->_patch($data);
$resolve($this);
}, $reject);
}, $reject);
}));
} | [
"function",
"edit",
"(",
"array",
"$",
"options",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"data",
"[",
... | Edits the webhook. Resolves with $this.
Options are as following (at least one is required):
```
array(
'name' => string,
'avatar' => string, (data, filepath or URL)
'channel' => \CharlotteDunois\Yasmin\Models\TextChannel|string
)
```
@param array $options
@param string $reason
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException | [
"Edits",
"the",
"webhook",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Webhook.php#L108-L139 |
CharlotteDunois/Yasmin | src/Models/Webhook.php | Webhook.delete | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$method = 'deleteWebhook';
$args = array($this->id, $reason);
if(!empty($this->token)) {
$method = 'deleteWebhookToken';
$args = array($this->id, $this->token, $reason);
}
$this->client->apimanager()->endpoints->webhook->$method(...$args)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | php | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$method = 'deleteWebhook';
$args = array($this->id, $reason);
if(!empty($this->token)) {
$method = 'deleteWebhookToken';
$args = array($this->id, $this->token, $reason);
}
$this->client->apimanager()->endpoints->webhook->$method(...$args)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | [
"function",
"delete",
"(",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"use",
"(",
"$",
"r... | Deletes the webhook.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Deletes",
"the",
"webhook",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Webhook.php#L146-L160 |
CharlotteDunois/Yasmin | src/Models/Webhook.php | Webhook.executeWebhook | protected function executeWebhook(array $opts, array $files) {
return $this->client->apimanager()->endpoints->webhook->executeWebhook($this->id, $this->token, $opts, $files, array('wait' => true))->then(function ($data) {
$channel = $this->client->channels->get($this->channelID);
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\TextChannelInterface) {
return $channel->_createMessage($data);
}
return $data;
});
} | php | protected function executeWebhook(array $opts, array $files) {
return $this->client->apimanager()->endpoints->webhook->executeWebhook($this->id, $this->token, $opts, $files, array('wait' => true))->then(function ($data) {
$channel = $this->client->channels->get($this->channelID);
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\TextChannelInterface) {
return $channel->_createMessage($data);
}
return $data;
});
} | [
"protected",
"function",
"executeWebhook",
"(",
"array",
"$",
"opts",
",",
"array",
"$",
"files",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"apimanager",
"(",
")",
"->",
"endpoints",
"->",
"webhook",
"->",
"executeWebhook",
"(",
"$",
"this",
... | Executes the webhook effectively. Resolves with an instance of Message.
@param array $opts
@param array $files
@return \React\Promise\ExtendedPromiseInterface
@internal | [
"Executes",
"the",
"webhook",
"effectively",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"Message",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Webhook.php#L287-L296 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.resolve | function resolve($channel) {
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\ChannelInterface) {
return $channel;
}
if(\is_int($channel)) {
$channel = (string) $channel;
}
if(\is_string($channel) && parent::has($channel)) {
return parent::get($channel);
}
throw new \InvalidArgumentException('Unable to resolve unknown channel');
} | php | function resolve($channel) {
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\ChannelInterface) {
return $channel;
}
if(\is_int($channel)) {
$channel = (string) $channel;
}
if(\is_string($channel) && parent::has($channel)) {
return parent::get($channel);
}
throw new \InvalidArgumentException('Unable to resolve unknown channel');
} | [
"function",
"resolve",
"(",
"$",
"channel",
")",
"{",
"if",
"(",
"$",
"channel",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Interfaces",
"\\",
"ChannelInterface",
")",
"{",
"return",
"$",
"channel",
";",
"}",
"if",
"(",
"\\",
"is_int",
... | Resolves given data to a channel.
@param \CharlotteDunois\Yasmin\Interfaces\ChannelInterface|string|int $channel string/int = channel ID
@return \CharlotteDunois\Yasmin\Interfaces\ChannelInterface
@throws \InvalidArgumentException | [
"Resolves",
"given",
"data",
"to",
"a",
"channel",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L45-L59 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.set | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->channels) {
$this->client->channels->set($key, $value);
}
return $this;
} | php | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->channels) {
$this->client->channels->set($key, $value);
}
return $this;
} | [
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"channels",
")",
"{",
"$",
"this",
"->",
"... | {@inheritdoc}
@param string $key
@param \CharlotteDunois\Yasmin\Interfaces\ChannelInterface $value
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L85-L92 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.delete | function delete($key) {
parent::delete($key);
if($this !== $this->client->channels) {
$this->client->channels->delete($key);
}
return $this;
} | php | function delete($key) {
parent::delete($key);
if($this !== $this->client->channels) {
$this->client->channels->delete($key);
}
return $this;
} | [
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"parent",
"::",
"delete",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"channels",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"channels",
"->",
"de... | {@inheritdoc}
@param string $key
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L99-L106 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.clear | function clear() {
if($this !== $this->client->channels) {
foreach($this->data as $key => $val) {
$this->client->channels->delete($key);
unset($val);
}
}
parent::clear();
return $this;
} | php | function clear() {
if($this !== $this->client->channels) {
foreach($this->data as $key => $val) {
$this->client->channels->delete($key);
unset($val);
}
}
parent::clear();
return $this;
} | [
"function",
"clear",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"channels",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"client",
"-... | {@inheritdoc}
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L112-L122 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.factory | function factory(array $data, ?\CharlotteDunois\Yasmin\Models\Guild $guild = null) {
if($guild === null) {
$guild = (!empty($data['guild_id']) ? $this->client->guilds->get($data['guild_id']) : null);
}
if(parent::has($data['id'])) {
$channel = parent::get($data['id']);
$channel->_patch($data);
return $channel;
}
switch($data['type']) {
default:
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown channel type');
break;
case 0:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\TextChannel($this->client, $guild, $data);
break;
case 1:
$channel = new \CharlotteDunois\Yasmin\Models\DMChannel($this->client, $data);
break;
case 2:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\VoiceChannel($this->client, $guild, $data);
break;
case 3:
$channel = new \CharlotteDunois\Yasmin\Models\GroupDMChannel($this->client, $data);
break;
case 4:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\CategoryChannel($this->client, $guild, $data);
break;
case 6:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\GuildStoreChannel($this->client, $guild, $data);
break;
}
$this->set($channel->id, $channel);
if($guild) {
$guild->channels->set($channel->id, $channel);
}
return $channel;
} | php | function factory(array $data, ?\CharlotteDunois\Yasmin\Models\Guild $guild = null) {
if($guild === null) {
$guild = (!empty($data['guild_id']) ? $this->client->guilds->get($data['guild_id']) : null);
}
if(parent::has($data['id'])) {
$channel = parent::get($data['id']);
$channel->_patch($data);
return $channel;
}
switch($data['type']) {
default:
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown channel type');
break;
case 0:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\TextChannel($this->client, $guild, $data);
break;
case 1:
$channel = new \CharlotteDunois\Yasmin\Models\DMChannel($this->client, $data);
break;
case 2:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\VoiceChannel($this->client, $guild, $data);
break;
case 3:
$channel = new \CharlotteDunois\Yasmin\Models\GroupDMChannel($this->client, $data);
break;
case 4:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\CategoryChannel($this->client, $guild, $data);
break;
case 6:
if($guild === null) {
throw new \CharlotteDunois\Yasmin\DiscordException('Unknown guild for guild channel');
}
$channel = new \CharlotteDunois\Yasmin\Models\GuildStoreChannel($this->client, $guild, $data);
break;
}
$this->set($channel->id, $channel);
if($guild) {
$guild->channels->set($channel->id, $channel);
}
return $channel;
} | [
"function",
"factory",
"(",
"array",
"$",
"data",
",",
"?",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"Guild",
"$",
"guild",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"guild",
"===",
"null",
")",
"{",
"$",
"guild",
"=",
"(",
"!",
... | Factory to create (or retrieve existing) channels.
@param array $data
@param \CharlotteDunois\Yasmin\Models\Guild|null $guilds
@return \CharlotteDunois\Yasmin\Interfaces\ChannelInterface
@throws \CharlotteDunois\Yasmin\DiscordException
@internal | [
"Factory",
"to",
"create",
"(",
"or",
"retrieve",
"existing",
")",
"channels",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L132-L190 |
CharlotteDunois/Yasmin | src/Models/ChannelStorage.php | ChannelStorage.getTypeForChannel | static function getTypeForChannel(\CharlotteDunois\Yasmin\Interfaces\ChannelInterface $channel) {
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GroupDMChannelInterface) {
return self::CHANNEL_TYPES['group'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\DMChannelInterface) {
return self::CHANNEL_TYPES['dm'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildVoiceChannelInterface) {
return self::CHANNEL_TYPES['voice'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\CategoryChannelInterface) {
return self::CHANNEL_TYPES['category'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildNewsChannelInterface) {
return self::CHANNEL_TYPES['news'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildStoreChannelInterface) {
return self::CHANNEL_TYPES['store'];
}
return self::CHANNEL_TYPES['text'];
} | php | static function getTypeForChannel(\CharlotteDunois\Yasmin\Interfaces\ChannelInterface $channel) {
if($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GroupDMChannelInterface) {
return self::CHANNEL_TYPES['group'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\DMChannelInterface) {
return self::CHANNEL_TYPES['dm'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildVoiceChannelInterface) {
return self::CHANNEL_TYPES['voice'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\CategoryChannelInterface) {
return self::CHANNEL_TYPES['category'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildNewsChannelInterface) {
return self::CHANNEL_TYPES['news'];
} elseif($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildStoreChannelInterface) {
return self::CHANNEL_TYPES['store'];
}
return self::CHANNEL_TYPES['text'];
} | [
"static",
"function",
"getTypeForChannel",
"(",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Interfaces",
"\\",
"ChannelInterface",
"$",
"channel",
")",
"{",
"if",
"(",
"$",
"channel",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Interfaces",
... | Get the type for the channel.
@param \CharlotteDunois\Yasmin\Interfaces\ChannelInterface $channel
@return int | [
"Get",
"the",
"type",
"for",
"the",
"channel",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/ChannelStorage.php#L197-L213 |
CharlotteDunois/Yasmin | src/Utils/DataHelpers.php | DataHelpers.resolveColor | static function resolveColor($color) {
if(\is_int($color)) {
return $color;
}
if(!\is_array($color)) {
return \hexdec(((string) $color));
}
if(\count($color) < 1) {
throw new \InvalidArgumentException('Color "'.\var_export($color, true).'" is not resolvable');
}
return (($color[0] << 16) + (($color[1] ?? 0) << 8) + ($color[2] ?? 0));
} | php | static function resolveColor($color) {
if(\is_int($color)) {
return $color;
}
if(!\is_array($color)) {
return \hexdec(((string) $color));
}
if(\count($color) < 1) {
throw new \InvalidArgumentException('Color "'.\var_export($color, true).'" is not resolvable');
}
return (($color[0] << 16) + (($color[1] ?? 0) << 8) + ($color[2] ?? 0));
} | [
"static",
"function",
"resolveColor",
"(",
"$",
"color",
")",
"{",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"color",
")",
")",
"{",
"return",
"$",
"color",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"color",
")",
")",
"{",
"return",
"\\",
... | Resolves a color to an integer.
@param array|int|string $color
@return int
@throws \InvalidArgumentException | [
"Resolves",
"a",
"color",
"to",
"an",
"integer",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/DataHelpers.php#L22-L36 |
CharlotteDunois/Yasmin | src/Utils/DataHelpers.php | DataHelpers.makeDateTime | static function makeDateTime(int $timestamp) {
$zone = new \DateTimeZone(\date_default_timezone_get());
return (new \DateTime('@'.$timestamp))->setTimezone($zone);
} | php | static function makeDateTime(int $timestamp) {
$zone = new \DateTimeZone(\date_default_timezone_get());
return (new \DateTime('@'.$timestamp))->setTimezone($zone);
} | [
"static",
"function",
"makeDateTime",
"(",
"int",
"$",
"timestamp",
")",
"{",
"$",
"zone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"\\",
"date_default_timezone_get",
"(",
")",
")",
";",
"return",
"(",
"new",
"\\",
"DateTime",
"(",
"'@'",
".",
"$",
"timest... | Makes a DateTime instance from an UNIX timestamp and applies the default timezone.
@param int $timestamp
@return \DateTime | [
"Makes",
"a",
"DateTime",
"instance",
"from",
"an",
"UNIX",
"timestamp",
"and",
"applies",
"the",
"default",
"timezone",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/DataHelpers.php#L43-L46 |
CharlotteDunois/Yasmin | src/Utils/DataHelpers.php | DataHelpers.makeBase64URI | static function makeBase64URI(string $data) {
$img = \getimagesizefromstring($data);
if(!$img) {
throw new \InvalidArgumentException('Bad input data');
}
return 'data:'.$img['mime'].';base64,'.\base64_encode($data);
} | php | static function makeBase64URI(string $data) {
$img = \getimagesizefromstring($data);
if(!$img) {
throw new \InvalidArgumentException('Bad input data');
}
return 'data:'.$img['mime'].';base64,'.\base64_encode($data);
} | [
"static",
"function",
"makeBase64URI",
"(",
"string",
"$",
"data",
")",
"{",
"$",
"img",
"=",
"\\",
"getimagesizefromstring",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"$",
"img",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Bad i... | Turns input into a base64-encoded data URI.
@param string $data
@return string
@throws \InvalidArgumentException | [
"Turns",
"input",
"into",
"a",
"base64",
"-",
"encoded",
"data",
"URI",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/DataHelpers.php#L54-L61 |
CharlotteDunois/Yasmin | src/Utils/DataHelpers.php | DataHelpers.typecastVariable | static function typecastVariable($variable, string $type) {
if($variable === null) {
return null;
}
switch($type) {
case 'array':
$variable = (array) $variable;
break;
case 'bool':
$variable = (bool) $variable;
break;
case 'float':
$variable = (float) $variable;
break;
case 'int':
$variable = (int) $variable;
break;
case 'string':
$variable = (string) $variable;
break;
default:
throw new \InvalidArgumentException('Unsupported type "'.$type.'"');
break;
}
return $variable;
} | php | static function typecastVariable($variable, string $type) {
if($variable === null) {
return null;
}
switch($type) {
case 'array':
$variable = (array) $variable;
break;
case 'bool':
$variable = (bool) $variable;
break;
case 'float':
$variable = (float) $variable;
break;
case 'int':
$variable = (int) $variable;
break;
case 'string':
$variable = (string) $variable;
break;
default:
throw new \InvalidArgumentException('Unsupported type "'.$type.'"');
break;
}
return $variable;
} | [
"static",
"function",
"typecastVariable",
"(",
"$",
"variable",
",",
"string",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"variable",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'array'",
":",
"$",
... | Typecasts the variable to the type, if not null.
@param mixed &$variable
@param string $type
@return mixed|null
@throws \InvalidArgumentException | [
"Typecasts",
"the",
"variable",
"to",
"the",
"type",
"if",
"not",
"null",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/DataHelpers.php#L70-L97 |
CharlotteDunois/Yasmin | src/Utils/DataHelpers.php | DataHelpers.applyOptions | static function applyOptions(array $input, array $options) {
$data = array();
foreach($input as $key => $val) {
if(!isset($options[$key])) {
continue;
}
if(\is_array($options[$key])) {
if(!empty($options[$key]['parse'])) {
$call = $options[$key]['parse'];
$val = $call($val);
}
if(!empty($options[$key]['type'])) {
$val = self::typecastVariable($val, $options[$key]['type']);
}
$key = $options[$key]['key'] ?? $key;
} elseif(!empty($options[$key])) {
$key = $options[$key];
}
$data[$key] = $val;
}
return $data;
} | php | static function applyOptions(array $input, array $options) {
$data = array();
foreach($input as $key => $val) {
if(!isset($options[$key])) {
continue;
}
if(\is_array($options[$key])) {
if(!empty($options[$key]['parse'])) {
$call = $options[$key]['parse'];
$val = $call($val);
}
if(!empty($options[$key]['type'])) {
$val = self::typecastVariable($val, $options[$key]['type']);
}
$key = $options[$key]['key'] ?? $key;
} elseif(!empty($options[$key])) {
$key = $options[$key];
}
$data[$key] = $val;
}
return $data;
} | [
"static",
"function",
"applyOptions",
"(",
"array",
"$",
"input",
",",
"array",
"$",
"options",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"isset... | Converts the input to the specified options.
Options is
```
array(
key => null|newKey|array('key' => newKey, 'type' => string, 'parse' => callable)
)
```
@param array $input
@param array $options
@return array | [
"Converts",
"the",
"input",
"to",
"the",
"specified",
"options",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/DataHelpers.php#L112-L139 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.bulkDelete | function bulkDelete($messages, string $reason = '', bool $filterOldMessages = false) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($messages, $reason, $filterOldMessages) {
if(\is_numeric($messages)) {
$messages = $this->fetchMessages(array('limit' => (int) $messages));
} else {
$messages = \React\Promise\resolve($messages);
}
$messages->done(function ($messages) use ($reason, $filterOldMessages, $resolve, $reject) {
if($messages instanceof \CharlotteDunois\Collect\Collection) {
$messages = $messages->all();
}
if($filterOldMessages) {
$messages = \array_filter($messages, function ($message) {
if($message instanceof \CharlotteDunois\Yasmin\Models\Message) {
$timestamp = $message->createdTimestamp;
} else {
$timestamp = (int) \CharlotteDunois\Yasmin\Utils\Snowflake::deconstruct($message)->timestamp;
}
return ((\time() - $timestamp) < 1209600);
});
}
$messages = \array_map(function ($message) {
return $message->id;
}, $messages);
if(\count($messages) < 2 || \count($messages) > 100) {
return $reject(new \InvalidArgumentException('Unable to bulk delete less than 2 or more than 100 messages'));
}
$this->client->apimanager()->endpoints->channel->bulkDeleteMessages($this->id, $messages, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}, $reject);
}));
} | php | function bulkDelete($messages, string $reason = '', bool $filterOldMessages = false) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($messages, $reason, $filterOldMessages) {
if(\is_numeric($messages)) {
$messages = $this->fetchMessages(array('limit' => (int) $messages));
} else {
$messages = \React\Promise\resolve($messages);
}
$messages->done(function ($messages) use ($reason, $filterOldMessages, $resolve, $reject) {
if($messages instanceof \CharlotteDunois\Collect\Collection) {
$messages = $messages->all();
}
if($filterOldMessages) {
$messages = \array_filter($messages, function ($message) {
if($message instanceof \CharlotteDunois\Yasmin\Models\Message) {
$timestamp = $message->createdTimestamp;
} else {
$timestamp = (int) \CharlotteDunois\Yasmin\Utils\Snowflake::deconstruct($message)->timestamp;
}
return ((\time() - $timestamp) < 1209600);
});
}
$messages = \array_map(function ($message) {
return $message->id;
}, $messages);
if(\count($messages) < 2 || \count($messages) > 100) {
return $reject(new \InvalidArgumentException('Unable to bulk delete less than 2 or more than 100 messages'));
}
$this->client->apimanager()->endpoints->channel->bulkDeleteMessages($this->id, $messages, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}, $reject);
}));
} | [
"function",
"bulkDelete",
"(",
"$",
"messages",
",",
"string",
"$",
"reason",
"=",
"''",
",",
"bool",
"$",
"filterOldMessages",
"=",
"false",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable... | Deletes multiple messages at once. Resolves with $this.
@param \CharlotteDunois\Collect\Collection|array|int $messages A collection or array of Message instances, or the number of messages to delete (2-100).
@param string $reason
@param bool $filterOldMessages Automatically filters out too old messages (14 days).
@return \React\Promise\ExtendedPromiseInterface | [
"Deletes",
"multiple",
"messages",
"at",
"once",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L68-L106 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.collectMessages | function collectMessages(callable $filter, array $options = array()) {
$mhandler = function (\CharlotteDunois\Yasmin\Models\Message $message) {
return array($message->id, $message);
};
$mfilter = function (\CharlotteDunois\Yasmin\Models\Message $message) use ($filter) {
return ($message->channel->getId() === $this->id && $filter($message));
};
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($this->client, 'message', $mhandler, $mfilter, $options);
return $collector->collect();
} | php | function collectMessages(callable $filter, array $options = array()) {
$mhandler = function (\CharlotteDunois\Yasmin\Models\Message $message) {
return array($message->id, $message);
};
$mfilter = function (\CharlotteDunois\Yasmin\Models\Message $message) use ($filter) {
return ($message->channel->getId() === $this->id && $filter($message));
};
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($this->client, 'message', $mhandler, $mfilter, $options);
return $collector->collect();
} | [
"function",
"collectMessages",
"(",
"callable",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"mhandler",
"=",
"function",
"(",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"Message",
"$",
"message",
... | Collects messages during a specific duration (and max. amount). Resolves with a Collection of Message instances, mapped by their IDs.
Options are as following (all are optional):
```
array(
'max' => int, (max. messages to collect)
'time' => int, (duration, in seconds, default 30)
'errors' => array, (optional, which failed "conditions" (max not reached in time ("time")) lead to a rejected promise, defaults to [])
)
```
@param callable $filter The filter to only collect desired messages. Signature: `function (Message $message): bool`
@param array $options The collector options.
@return \React\Promise\ExtendedPromiseInterface This promise is cancellable.
@throws \RangeException The exception the promise gets rejected with, if collecting times out.
@throws \OutOfBoundsException The exception the promise gets rejected with, if the promise gets cancelled.
@see \CharlotteDunois\Yasmin\Models\Message
@see \CharlotteDunois\Yasmin\Utils\Collector | [
"Collects",
"messages",
"during",
"a",
"specific",
"duration",
"(",
"and",
"max",
".",
"amount",
")",
".",
"Resolves",
"with",
"a",
"Collection",
"of",
"Message",
"instances",
"mapped",
"by",
"their",
"IDs",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L129-L139 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.fetchMessage | function fetchMessage(string $id) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($id) {
$this->client->apimanager()->endpoints->channel->getChannelMessage($this->id, $id)->done(function ($data) use ($resolve) {
$message = $this->_createMessage($data);
$resolve($message);
}, $reject);
}));
} | php | function fetchMessage(string $id) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($id) {
$this->client->apimanager()->endpoints->channel->getChannelMessage($this->id, $id)->done(function ($data) use ($resolve) {
$message = $this->_createMessage($data);
$resolve($message);
}, $reject);
}));
} | [
"function",
"fetchMessage",
"(",
"string",
"$",
"id",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"use",
"(",
"$",
"id",
")",
... | Fetches a specific message using the ID. Resolves with an instance of Message.
@param string $id
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Models\Message | [
"Fetches",
"a",
"specific",
"message",
"using",
"the",
"ID",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"Message",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L147-L154 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.fetchMessages | function fetchMessages(array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($options) {
$this->client->apimanager()->endpoints->channel->getChannelMessages($this->id, $options)->done(function ($data) use ($resolve) {
$collect = new \CharlotteDunois\Collect\Collection();
foreach($data as $m) {
$message = $this->_createMessage($m);
$collect->set($message->id, $message);
}
$resolve($collect);
}, $reject);
}));
} | php | function fetchMessages(array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($options) {
$this->client->apimanager()->endpoints->channel->getChannelMessages($this->id, $options)->done(function ($data) use ($resolve) {
$collect = new \CharlotteDunois\Collect\Collection();
foreach($data as $m) {
$message = $this->_createMessage($m);
$collect->set($message->id, $message);
}
$resolve($collect);
}, $reject);
}));
} | [
"function",
"fetchMessages",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"... | Fetches messages of this channel. Resolves with a Collection of Message instances, mapped by their ID.
Options are as following:
```
array(
'after' => string, (message ID)
'around' => string, (message ID)
'before' => string, (message ID)
'limit' => int, (1-100, defaults to 50)
)
```
@param array $options
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Models\Message | [
"Fetches",
"messages",
"of",
"this",
"channel",
".",
"Resolves",
"with",
"a",
"Collection",
"of",
"Message",
"instances",
"mapped",
"by",
"their",
"ID",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L174-L187 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.getLastMessage | function getLastMessage() {
if(!empty($this->lastMessageID) && $this->messages->has($this->lastMessageID)) {
return $this->messages->get($this->lastMessageID);
}
return null;
} | php | function getLastMessage() {
if(!empty($this->lastMessageID) && $this->messages->has($this->lastMessageID)) {
return $this->messages->get($this->lastMessageID);
}
return null;
} | [
"function",
"getLastMessage",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"lastMessageID",
")",
"&&",
"$",
"this",
"->",
"messages",
"->",
"has",
"(",
"$",
"this",
"->",
"lastMessageID",
")",
")",
"{",
"return",
"$",
"this",
"->",... | Gets the last message in this channel if cached, or null.
@return \CharlotteDunois\Yasmin\Models\Message|null | [
"Gets",
"the",
"last",
"message",
"in",
"this",
"channel",
"if",
"cached",
"or",
"null",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L193-L199 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.send | function send(string $content, array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($content, $options) {
\CharlotteDunois\Yasmin\Utils\MessageHelpers::resolveMessageOptionsFiles($options)->done(function ($files) use ($content, $options, $resolve, $reject) {
$msg = array(
'content' => $content
);
if(!empty($options['embed'])) {
$msg['embed'] = $options['embed'];
}
if(!empty($options['nonce'])) {
$msg['nonce'] = $options['nonce'];
}
$disableEveryone = (isset($options['disableEveryone']) ? ((bool) $options['disableEveryone']) : $this->client->getOption('disableEveryone', true));
if($disableEveryone) {
$msg['content'] = \str_replace(array('@everyone', '@here'), array("@\u{200b}everyone", "@\u{200b}here"), $msg['content']);
}
if(!empty($options['tts'])) {
$msg['tts'] = true;
}
if(isset($options['split'])) {
$options['split'] = $split = \array_merge(\CharlotteDunois\Yasmin\Models\Message::DEFAULT_SPLIT_OPTIONS, (\is_array($options['split']) ? $options['split'] : array()));
$messages = \CharlotteDunois\Yasmin\Utils\MessageHelpers::splitMessage($msg['content'], $options['split']);
if(\count($messages) > 1) {
$collection = new \CharlotteDunois\Collect\Collection();
$i = \count($messages);
$chunkedSend = function ($msg, $files = null) use ($collection, $reject) {
return $this->client->apimanager()->endpoints->channel->createMessage($this->id, $msg, ($files ?? array()))->then(function ($response) use ($collection) {
$msg = $this->_createMessage($response);
$collection->set($msg->id, $msg);
}, $reject);
};
$promise = \React\Promise\resolve();
foreach($messages as $key => $message) {
$promise = $promise->then(function () use ($chunkedSend, &$files, $key, $i, $message, &$msg, $split) {
$fs = null;
if($files) {
$fs = $files;
$files = null;
}
$message = array(
'content' => ($key > 0 ? $split['before'] : '').$message.($key < $i ? $split['after'] : '')
);
if(!empty($msg['embed'])) {
$message['embed'] = $msg['embed'];
$msg['embed'] = null;
}
return $chunkedSend($message, $fs);
}, $reject);
}
return $promise->done(function () use ($collection, $resolve) {
$resolve($collection);
}, $reject);
}
}
$this->client->apimanager()->endpoints->channel->createMessage($this->id, $msg, ($files ?? array()))->done(function ($response) use ($resolve) {
$resolve($this->_createMessage($response));
}, $reject);
}, $reject);
}));
} | php | function send(string $content, array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($content, $options) {
\CharlotteDunois\Yasmin\Utils\MessageHelpers::resolveMessageOptionsFiles($options)->done(function ($files) use ($content, $options, $resolve, $reject) {
$msg = array(
'content' => $content
);
if(!empty($options['embed'])) {
$msg['embed'] = $options['embed'];
}
if(!empty($options['nonce'])) {
$msg['nonce'] = $options['nonce'];
}
$disableEveryone = (isset($options['disableEveryone']) ? ((bool) $options['disableEveryone']) : $this->client->getOption('disableEveryone', true));
if($disableEveryone) {
$msg['content'] = \str_replace(array('@everyone', '@here'), array("@\u{200b}everyone", "@\u{200b}here"), $msg['content']);
}
if(!empty($options['tts'])) {
$msg['tts'] = true;
}
if(isset($options['split'])) {
$options['split'] = $split = \array_merge(\CharlotteDunois\Yasmin\Models\Message::DEFAULT_SPLIT_OPTIONS, (\is_array($options['split']) ? $options['split'] : array()));
$messages = \CharlotteDunois\Yasmin\Utils\MessageHelpers::splitMessage($msg['content'], $options['split']);
if(\count($messages) > 1) {
$collection = new \CharlotteDunois\Collect\Collection();
$i = \count($messages);
$chunkedSend = function ($msg, $files = null) use ($collection, $reject) {
return $this->client->apimanager()->endpoints->channel->createMessage($this->id, $msg, ($files ?? array()))->then(function ($response) use ($collection) {
$msg = $this->_createMessage($response);
$collection->set($msg->id, $msg);
}, $reject);
};
$promise = \React\Promise\resolve();
foreach($messages as $key => $message) {
$promise = $promise->then(function () use ($chunkedSend, &$files, $key, $i, $message, &$msg, $split) {
$fs = null;
if($files) {
$fs = $files;
$files = null;
}
$message = array(
'content' => ($key > 0 ? $split['before'] : '').$message.($key < $i ? $split['after'] : '')
);
if(!empty($msg['embed'])) {
$message['embed'] = $msg['embed'];
$msg['embed'] = null;
}
return $chunkedSend($message, $fs);
}, $reject);
}
return $promise->done(function () use ($collection, $resolve) {
$resolve($collection);
}, $reject);
}
}
$this->client->apimanager()->endpoints->channel->createMessage($this->id, $msg, ($files ?? array()))->done(function ($response) use ($resolve) {
$resolve($this->_createMessage($response));
}, $reject);
}, $reject);
}));
} | [
"function",
"send",
"(",
"string",
"$",
"content",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",... | Sends a message to a channel. Resolves with an instance of Message, or a Collection of Message instances, mapped by their ID.
Options are as following (all are optional):
```
array(
'embed' => array|\CharlotteDunois\Yasmin\Models\MessageEmbed, (an (embed) array/object or an instance of MessageEmbed)
'files' => array, (an array of `[ 'name' => string, 'data' => string || 'path' => string ]` or just plain file contents, file paths or URLs)
'nonce' => string, (a snowflake used for optimistic sending)
'disableEveryone' => bool, (whether @everyone and @here should be replaced with plaintext, defaults to client option disableEveryone)
'tts' => bool,
'split' => bool|array, (*)
)
* array(
* 'before' => string, (The string to insert before the split)
* 'after' => string, (The string to insert after the split)
* 'char' => string, (The string to split on)
* 'maxLength' => int, (The max. length of each message)
* )
```
@param string $content The message content.
@param array $options Any message options.
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Models\Message | [
"Sends",
"a",
"message",
"to",
"a",
"channel",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"Message",
"or",
"a",
"Collection",
"of",
"Message",
"instances",
"mapped",
"by",
"their",
"ID",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L229-L301 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.startTyping | function startTyping() {
if($this->typingTriggered['count'] === 0) {
$fn = function () {
$this->client->apimanager()->endpoints->channel->triggerChannelTyping($this->id)->done(function () {
$this->_updateTyping($this->client->user, \time());
}, function () {
$this->_updateTyping($this->client->user);
$this->typingTriggered['count'] = 0;
if($this->typingTriggered['timer']) {
$this->client->cancelTimer($this->typingTriggered['timer']);
$this->typingTriggered['timer'] = null;
}
});
};
$this->typingTriggered['timer'] = $this->client->addPeriodicTimer(7, $fn);
$fn();
}
$this->typingTriggered['count']++;
} | php | function startTyping() {
if($this->typingTriggered['count'] === 0) {
$fn = function () {
$this->client->apimanager()->endpoints->channel->triggerChannelTyping($this->id)->done(function () {
$this->_updateTyping($this->client->user, \time());
}, function () {
$this->_updateTyping($this->client->user);
$this->typingTriggered['count'] = 0;
if($this->typingTriggered['timer']) {
$this->client->cancelTimer($this->typingTriggered['timer']);
$this->typingTriggered['timer'] = null;
}
});
};
$this->typingTriggered['timer'] = $this->client->addPeriodicTimer(7, $fn);
$fn();
}
$this->typingTriggered['count']++;
} | [
"function",
"startTyping",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"typingTriggered",
"[",
"'count'",
"]",
"===",
"0",
")",
"{",
"$",
"fn",
"=",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"apimanager",
"(",
")",
"->",
"endpo... | Starts sending the typing indicator in this channel. Counts up a triggered typing counter.
@return void | [
"Starts",
"sending",
"the",
"typing",
"indicator",
"in",
"this",
"channel",
".",
"Counts",
"up",
"a",
"triggered",
"typing",
"counter",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L307-L328 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.stopTyping | function stopTyping(bool $force = false) {
if($this->typingTriggered['count'] === 0) {
return;
}
$this->typingTriggered['count']--;
if($force) {
$this->typingTriggered['count'] = 0;
}
if($this->typingTriggered['count'] === 0) {
if($this->typingTriggered['timer']) {
$this->client->cancelTimer($this->typingTriggered['timer']);
$this->typingTriggered['timer'] = null;
}
}
} | php | function stopTyping(bool $force = false) {
if($this->typingTriggered['count'] === 0) {
return;
}
$this->typingTriggered['count']--;
if($force) {
$this->typingTriggered['count'] = 0;
}
if($this->typingTriggered['count'] === 0) {
if($this->typingTriggered['timer']) {
$this->client->cancelTimer($this->typingTriggered['timer']);
$this->typingTriggered['timer'] = null;
}
}
} | [
"function",
"stopTyping",
"(",
"bool",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"typingTriggered",
"[",
"'count'",
"]",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"typingTriggered",
"[",
"'count'",
"]",
"-... | Stops sending the typing indicator in this channel. Counts down a triggered typing counter.
@param bool $force Reset typing counter and stop sending the indicator.
@return void | [
"Stops",
"sending",
"the",
"typing",
"indicator",
"in",
"this",
"channel",
".",
"Counts",
"down",
"a",
"triggered",
"typing",
"counter",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L335-L351 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.isTyping | function isTyping(\CharlotteDunois\Yasmin\Models\User $user) {
return $this->typings->has($user->id);
} | php | function isTyping(\CharlotteDunois\Yasmin\Models\User $user) {
return $this->typings->has($user->id);
} | [
"function",
"isTyping",
"(",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"User",
"$",
"user",
")",
"{",
"return",
"$",
"this",
"->",
"typings",
"->",
"has",
"(",
"$",
"user",
"->",
"id",
")",
";",
"}"
] | Determines whether the given user is typing in this channel or not.
@param \CharlotteDunois\Yasmin\Models\User $user
@return bool | [
"Determines",
"whether",
"the",
"given",
"user",
"is",
"typing",
"in",
"this",
"channel",
"or",
"not",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L366-L368 |
CharlotteDunois/Yasmin | src/Traits/TextChannelTrait.php | TextChannelTrait.isTypingSince | function isTypingSince(\CharlotteDunois\Yasmin\Models\User $user) {
if(!$this->isTyping($user)) {
return -1;
}
return (\time() - $this->typings->get($user->id)['timestamp']);
} | php | function isTypingSince(\CharlotteDunois\Yasmin\Models\User $user) {
if(!$this->isTyping($user)) {
return -1;
}
return (\time() - $this->typings->get($user->id)['timestamp']);
} | [
"function",
"isTypingSince",
"(",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"User",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isTyping",
"(",
"$",
"user",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
... | Determines whether how long the given user has been typing in this channel. Returns -1 if the user is not typing.
@param \CharlotteDunois\Yasmin\Models\User $user
@return int | [
"Determines",
"whether",
"how",
"long",
"the",
"given",
"user",
"has",
"been",
"typing",
"in",
"this",
"channel",
".",
"Returns",
"-",
"1",
"if",
"the",
"user",
"is",
"not",
"typing",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Traits/TextChannelTrait.php#L375-L381 |
CharlotteDunois/Yasmin | src/WebSocket/Compression/ZlibStream.php | ZlibStream.decompress | function decompress(string $data): string {
if(!$this->context) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('No inflate context initialized');
}
$uncompressed = \inflate_add($this->context, $data);
if($uncompressed === false) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The inflate context was unable to decompress the data');
}
return $uncompressed;
} | php | function decompress(string $data): string {
if(!$this->context) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('No inflate context initialized');
}
$uncompressed = \inflate_add($this->context, $data);
if($uncompressed === false) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The inflate context was unable to decompress the data');
}
return $uncompressed;
} | [
"function",
"decompress",
"(",
"string",
"$",
"data",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
")",
"{",
"throw",
"new",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"WebSocket",
"\\",
"DiscordGatewayException",
"(",
"'No in... | Decompresses data.
@param string $data
@return string
@throws \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException | [
"Decompresses",
"data",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Compression/ZlibStream.php#L75-L86 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.resolve | function resolve($user) {
if($user instanceof \CharlotteDunois\Yasmin\Models\User) {
return $user;
}
if($user instanceof \CharlotteDunois\Yasmin\Models\GuildMember) {
return $user->user;
}
if(\is_int($user)) {
$user = (string) $user;
}
if(\is_string($user) && parent::has($user)) {
return parent::get($user);
}
throw new \InvalidArgumentException('Unable to resolve unknown user');
} | php | function resolve($user) {
if($user instanceof \CharlotteDunois\Yasmin\Models\User) {
return $user;
}
if($user instanceof \CharlotteDunois\Yasmin\Models\GuildMember) {
return $user->user;
}
if(\is_int($user)) {
$user = (string) $user;
}
if(\is_string($user) && parent::has($user)) {
return parent::get($user);
}
throw new \InvalidArgumentException('Unable to resolve unknown user');
} | [
"function",
"resolve",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"user",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"User",
")",
"{",
"return",
"$",
"user",
";",
"}",
"if",
"(",
"$",
"user",
"instanceof",
"\\",
"Ch... | Resolves given data to an user.
@param \CharlotteDunois\Yasmin\Models\User|\CharlotteDunois\Yasmin\Models\GuildMember|string|int $user string/int = user ID
@return \CharlotteDunois\Yasmin\Models\User
@throws \InvalidArgumentException | [
"Resolves",
"given",
"data",
"to",
"an",
"user",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L42-L60 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.patch | function patch(array $user) {
if(parent::has($user['id'])) {
return parent::get($user['id']);
}
if(count($user) === 1) {
return null;
}
return $this->factory($user);
} | php | function patch(array $user) {
if(parent::has($user['id'])) {
return parent::get($user['id']);
}
if(count($user) === 1) {
return null;
}
return $this->factory($user);
} | [
"function",
"patch",
"(",
"array",
"$",
"user",
")",
"{",
"if",
"(",
"parent",
"::",
"has",
"(",
"$",
"user",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"parent",
"::",
"get",
"(",
"$",
"user",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"cou... | Patches an user (retrieves the user if the user exists), returns null if only the ID is in the array, or creates an user.
@param array $user
@return \CharlotteDunois\Yasmin\Models\User|null | [
"Patches",
"an",
"user",
"(",
"retrieves",
"the",
"user",
"if",
"the",
"user",
"exists",
")",
"returns",
"null",
"if",
"only",
"the",
"ID",
"is",
"in",
"the",
"array",
"or",
"creates",
"an",
"user",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L67-L77 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.set | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->users) {
$this->client->users->set($key, $value);
}
return $this;
} | php | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->users) {
$this->client->users->set($key, $value);
}
return $this;
} | [
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"users",
")",
"{",
"$",
"this",
"->",
"cli... | {@inheritdoc}
@param string $key
@param \CharlotteDunois\Yasmin\Models\User $value
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L103-L110 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.delete | function delete($key) {
parent::delete($key);
if($this !== $this->client->users) {
$this->client->users->delete($key);
}
return $this;
} | php | function delete($key) {
parent::delete($key);
if($this !== $this->client->users) {
$this->client->users->delete($key);
}
return $this;
} | [
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"parent",
"::",
"delete",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"users",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"users",
"->",
"delete",... | {@inheritdoc}
@param string $key
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L117-L124 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.factory | function factory(array $data, bool $userFetched = false) {
if(parent::has($data['id'])) {
$user = parent::get($data['id']);
$user->_patch($data);
return $user;
}
$user = new \CharlotteDunois\Yasmin\Models\User($this->client, $data, false, $userFetched);
$this->set($user->id, $user);
return $user;
} | php | function factory(array $data, bool $userFetched = false) {
if(parent::has($data['id'])) {
$user = parent::get($data['id']);
$user->_patch($data);
return $user;
}
$user = new \CharlotteDunois\Yasmin\Models\User($this->client, $data, false, $userFetched);
$this->set($user->id, $user);
return $user;
} | [
"function",
"factory",
"(",
"array",
"$",
"data",
",",
"bool",
"$",
"userFetched",
"=",
"false",
")",
"{",
"if",
"(",
"parent",
"::",
"has",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"user",
"=",
"parent",
"::",
"get",
"(",
"$",
"... | Factory to create (or retrieve existing) users.
@param array $data
@param bool $userFetched
@return \CharlotteDunois\Yasmin\Models\User
@internal | [
"Factory",
"to",
"create",
"(",
"or",
"retrieve",
"existing",
")",
"users",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L133-L144 |
CharlotteDunois/Yasmin | src/Models/UserStorage.php | UserStorage.sweep | function sweep() {
$members = \array_unique($this->client->guilds->reduce(function ($carry, $g) {
return \array_merge($carry, \array_keys($g->members->all()));
}, array()));
$amount = 0;
foreach($this->data as $key => $val) {
if($val->id !== $this->client->user->id && !$val->userFetched && !\in_array($key, $members, true)) {
$this->client->presences->delete($key);
$this->delete($key);
unset($val);
$amount++;
}
}
return $amount;
} | php | function sweep() {
$members = \array_unique($this->client->guilds->reduce(function ($carry, $g) {
return \array_merge($carry, \array_keys($g->members->all()));
}, array()));
$amount = 0;
foreach($this->data as $key => $val) {
if($val->id !== $this->client->user->id && !$val->userFetched && !\in_array($key, $members, true)) {
$this->client->presences->delete($key);
$this->delete($key);
unset($val);
$amount++;
}
}
return $amount;
} | [
"function",
"sweep",
"(",
")",
"{",
"$",
"members",
"=",
"\\",
"array_unique",
"(",
"$",
"this",
"->",
"client",
"->",
"guilds",
"->",
"reduce",
"(",
"function",
"(",
"$",
"carry",
",",
"$",
"g",
")",
"{",
"return",
"\\",
"array_merge",
"(",
"$",
"... | Sweeps users falling out of scope (no mutual guilds). Returns the amount of sweeped users.
@return int | [
"Sweeps",
"users",
"falling",
"out",
"of",
"scope",
"(",
"no",
"mutual",
"guilds",
")",
".",
"Returns",
"the",
"amount",
"of",
"sweeped",
"users",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/UserStorage.php#L150-L167 |
CharlotteDunois/Yasmin | src/Utils/EventHelpers.php | EventHelpers.waitForEvent | static function waitForEvent($emitter, string $event, ?callable $filter = null, array $options = array()) {
$options['max'] = 1;
$options['time'] = $options['time'] ?? 0;
$options['errors'] = array('max');
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($emitter, $event, function (...$a) {
return [ 0, $a ];
}, $filter, $options);
return $collector->collect()->then(function (\CharlotteDunois\Collect\Collection $bucket) {
return $bucket->first();
});
} | php | static function waitForEvent($emitter, string $event, ?callable $filter = null, array $options = array()) {
$options['max'] = 1;
$options['time'] = $options['time'] ?? 0;
$options['errors'] = array('max');
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($emitter, $event, function (...$a) {
return [ 0, $a ];
}, $filter, $options);
return $collector->collect()->then(function (\CharlotteDunois\Collect\Collection $bucket) {
return $bucket->first();
});
} | [
"static",
"function",
"waitForEvent",
"(",
"$",
"emitter",
",",
"string",
"$",
"event",
",",
"?",
"callable",
"$",
"filter",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'max'",
"]",
"=",
"1",
"... | Waits for a specific type of event to get emitted. Additional filter may be applied to look for a specific event (invoked as `$filter(...$args)`). Resolves with an array of arguments (from the event).
Options may be:
```
array(
'time' => int, (if the event hasn't been found yet, this will define a timeout (in seconds) after which the promise gets rejected)
)
```
@param \CharlotteDunois\Events\EventEmitterInterface $emitter
@param string $event
@param callable|null $filter
@param array $options
@return \React\Promise\ExtendedPromiseInterface This promise is cancellable.
@throws \RangeException The exception the promise gets rejected with, if waiting times out.
@throws \OutOfBoundsException The exception the promise gets rejected with, if the promise gets cancelled. | [
"Waits",
"for",
"a",
"specific",
"type",
"of",
"event",
"to",
"get",
"emitted",
".",
"Additional",
"filter",
"may",
"be",
"applied",
"to",
"look",
"for",
"a",
"specific",
"event",
"(",
"invoked",
"as",
"$filter",
"(",
"...",
"$args",
")",
")",
".",
"Re... | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/EventHelpers.php#L34-L46 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setAuthor | function setAuthor($name, string $iconurl = '', string $url = '') {
$name = (string) $name;
if(\mb_strlen($name) > 256) {
throw new \InvalidArgumentException('Author name can not be longer than 256 characters.');
}
$this->author = array(
'name' => $name,
'icon_url' => $iconurl,
'url' => $url
);
return $this;
} | php | function setAuthor($name, string $iconurl = '', string $url = '') {
$name = (string) $name;
if(\mb_strlen($name) > 256) {
throw new \InvalidArgumentException('Author name can not be longer than 256 characters.');
}
$this->author = array(
'name' => $name,
'icon_url' => $iconurl,
'url' => $url
);
return $this;
} | [
"function",
"setAuthor",
"(",
"$",
"name",
",",
"string",
"$",
"iconurl",
"=",
"''",
",",
"string",
"$",
"url",
"=",
"''",
")",
"{",
"$",
"name",
"=",
"(",
"string",
")",
"$",
"name",
";",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"name",
")",
">... | Set the author of this embed.
@param string $name Maximum length is 256 characters.
@param string $iconurl The URL to the icon.
@param string $url The URL to the author.
@return $this
@throws \InvalidArgumentException | [
"Set",
"the",
"author",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L202-L216 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setColor | function setColor($color) {
$this->color = \CharlotteDunois\Yasmin\Utils\DataHelpers::resolveColor($color);
return $this;
} | php | function setColor($color) {
$this->color = \CharlotteDunois\Yasmin\Utils\DataHelpers::resolveColor($color);
return $this;
} | [
"function",
"setColor",
"(",
"$",
"color",
")",
"{",
"$",
"this",
"->",
"color",
"=",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Utils",
"\\",
"DataHelpers",
"::",
"resolveColor",
"(",
"$",
"color",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the color of this embed.
@param mixed $color
@return $this
@throws \InvalidArgumentException
@see \CharlotteDunois\Yasmin\Utils\DataHelpers::resolveColor() | [
"Set",
"the",
"color",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L225-L228 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setDescription | function setDescription($description) {
$description = (string) $description;
if(\mb_strlen($description) > 2048) {
throw new \InvalidArgumentException('Embed description can not be longer than 2048 characters');
}
$this->description = $description;
return $this;
} | php | function setDescription($description) {
$description = (string) $description;
if(\mb_strlen($description) > 2048) {
throw new \InvalidArgumentException('Embed description can not be longer than 2048 characters');
}
$this->description = $description;
return $this;
} | [
"function",
"setDescription",
"(",
"$",
"description",
")",
"{",
"$",
"description",
"=",
"(",
"string",
")",
"$",
"description",
";",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"description",
")",
">",
"2048",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgume... | Set the description of this embed.
@param string $description Maxiumum length is 2048 characters.
@return $this
@throws \InvalidArgumentException | [
"Set",
"the",
"description",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L236-L245 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setFooter | function setFooter($text, string $iconurl = '') {
$text = (string) $text;
if(\mb_strlen($text) > 2048) {
throw new \InvalidArgumentException('Footer text can not be longer than 2048 characters.');
}
$this->footer = array(
'text' => $text,
'icon_url' => $iconurl
);
return $this;
} | php | function setFooter($text, string $iconurl = '') {
$text = (string) $text;
if(\mb_strlen($text) > 2048) {
throw new \InvalidArgumentException('Footer text can not be longer than 2048 characters.');
}
$this->footer = array(
'text' => $text,
'icon_url' => $iconurl
);
return $this;
} | [
"function",
"setFooter",
"(",
"$",
"text",
",",
"string",
"$",
"iconurl",
"=",
"''",
")",
"{",
"$",
"text",
"=",
"(",
"string",
")",
"$",
"text",
";",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"text",
")",
">",
"2048",
")",
"{",
"throw",
"new",
"... | Set the footer of this embed.
@param string $text Maximum length is 2048 characters.
@param string $iconurl The URL to the icon.
@return $this
@throws \InvalidArgumentException | [
"Set",
"the",
"footer",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L254-L267 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setTimestamp | function setTimestamp(?int $timestamp = null) {
$this->timestamp = (new \DateTime(($timestamp !== null ? '@'.$timestamp : 'now')))->format('c');
return $this;
} | php | function setTimestamp(?int $timestamp = null) {
$this->timestamp = (new \DateTime(($timestamp !== null ? '@'.$timestamp : 'now')))->format('c');
return $this;
} | [
"function",
"setTimestamp",
"(",
"?",
"int",
"$",
"timestamp",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"timestamp",
"=",
"(",
"new",
"\\",
"DateTime",
"(",
"(",
"$",
"timestamp",
"!==",
"null",
"?",
"'@'",
".",
"$",
"timestamp",
":",
"'now'",
")",
... | Set the timestamp of this embed.
@param int|null $timestamp
@return $this | [
"Set",
"the",
"timestamp",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L294-L297 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.setTitle | function setTitle(string $title) {
if(\mb_strlen($title) > 256) {
throw new \InvalidArgumentException('Embed title can not be longer than 256 characters');
}
$this->title = $title;
return $this;
} | php | function setTitle(string $title) {
if(\mb_strlen($title) > 256) {
throw new \InvalidArgumentException('Embed title can not be longer than 256 characters');
}
$this->title = $title;
return $this;
} | [
"function",
"setTitle",
"(",
"string",
"$",
"title",
")",
"{",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"title",
")",
">",
"256",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Embed title can not be longer than 256 characters'",
")",
";",
"... | Set the title of this embed.
@param string $title Maximum length is 256 characters.
@return $this
@throws \InvalidArgumentException | [
"Set",
"the",
"title",
"of",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L305-L312 |
CharlotteDunois/Yasmin | src/Models/MessageEmbed.php | MessageEmbed.addField | function addField($title, $value, bool $inline = false) {
if(\count($this->fields) >= 25) {
throw new \RangeException('Embeds can not have more than 25 fields');
}
$title = (string) $title;
$value = (string) $value;
if(\mb_strlen($title) > 256) {
throw new \InvalidArgumentException('Embed title can not be longer than 256 characters');
}
if(\mb_strlen($value) > 1024) {
throw new \InvalidArgumentException('Embed value can not be longer than 1024 characters');
}
$this->fields[] = array(
'name' => $title,
'value' => $value,
'inline' => $inline
);
return $this;
} | php | function addField($title, $value, bool $inline = false) {
if(\count($this->fields) >= 25) {
throw new \RangeException('Embeds can not have more than 25 fields');
}
$title = (string) $title;
$value = (string) $value;
if(\mb_strlen($title) > 256) {
throw new \InvalidArgumentException('Embed title can not be longer than 256 characters');
}
if(\mb_strlen($value) > 1024) {
throw new \InvalidArgumentException('Embed value can not be longer than 1024 characters');
}
$this->fields[] = array(
'name' => $title,
'value' => $value,
'inline' => $inline
);
return $this;
} | [
"function",
"addField",
"(",
"$",
"title",
",",
"$",
"value",
",",
"bool",
"$",
"inline",
"=",
"false",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"fields",
")",
">=",
"25",
")",
"{",
"throw",
"new",
"\\",
"RangeException",
"(",
... | Adds a field to this embed.
@param string $title Maximum length is 256 characters.
@param string $value Maximum length is 1024 characters.
@param bool $inline Whether this field gets shown with other inline fields on one line.
@return $this
@throws \RangeException
@throws \InvalidArgumentException | [
"Adds",
"a",
"field",
"to",
"this",
"embed",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageEmbed.php#L333-L356 |
CharlotteDunois/Yasmin | src/Models/MessageReaction.php | MessageReaction.fetchUsers | function fetchUsers(int $limit = 100, string $before = '', string $after = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($limit, $before, $after) {
$query = array('limit' => $limit);
if(!empty($before)) {
$query['before'] = $before;
}
if(!empty($after)) {
$query['after'] = $after;
}
$this->client->apimanager()->endpoints->channel
->getMessageReactions($this->message->channel->getId(), $this->message->id, $this->emoji->identifier, $query)
->done(function ($data) use ($resolve) {
foreach($data as $react) {
$user = $this->client->users->patch($react);
$this->users->set($user->id, $user);
}
$resolve($this->users);
}, $reject);
}));
} | php | function fetchUsers(int $limit = 100, string $before = '', string $after = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($limit, $before, $after) {
$query = array('limit' => $limit);
if(!empty($before)) {
$query['before'] = $before;
}
if(!empty($after)) {
$query['after'] = $after;
}
$this->client->apimanager()->endpoints->channel
->getMessageReactions($this->message->channel->getId(), $this->message->id, $this->emoji->identifier, $query)
->done(function ($data) use ($resolve) {
foreach($data as $react) {
$user = $this->client->users->patch($react);
$this->users->set($user->id, $user);
}
$resolve($this->users);
}, $reject);
}));
} | [
"function",
"fetchUsers",
"(",
"int",
"$",
"limit",
"=",
"100",
",",
"string",
"$",
"before",
"=",
"''",
",",
"string",
"$",
"after",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
... | Fetches all the users that gave this reaction. Resolves with a Collection of User instances, mapped by their IDs.
@param int $limit The maximum amount of users to fetch, defaults to 100.
@param string $before Limit fetching users to those with an ID smaller than the given ID.
@param string $after Limit fetching users to those with an ID greater than the given ID.
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Models\User | [
"Fetches",
"all",
"the",
"users",
"that",
"gave",
"this",
"reaction",
".",
"Resolves",
"with",
"a",
"Collection",
"of",
"User",
"instances",
"mapped",
"by",
"their",
"IDs",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageReaction.php#L87-L110 |
CharlotteDunois/Yasmin | src/Models/MessageReaction.php | MessageReaction.remove | function remove($user = null) {
if($user !== null) {
$user = $this->client->users->resolve($user);
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($user) {
$this->client->apimanager()->endpoints->channel
->deleteMessageUserReaction($this->message->channel->getId(), $this->message->id, $this->emoji->identifier, ($user !== null ? $user->id : '@me'))
->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function remove($user = null) {
if($user !== null) {
$user = $this->client->users->resolve($user);
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($user) {
$this->client->apimanager()->endpoints->channel
->deleteMessageUserReaction($this->message->channel->getId(), $this->message->id, $this->emoji->identifier, ($user !== null ? $user->id : '@me'))
->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"remove",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"user",
"!==",
"null",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"client",
"->",
"users",
"->",
"resolve",
"(",
"$",
"user",
")",
";",
"}",
"return",
"(",
"new"... | Removes an user from the reaction. Resolves with $this.
@param \CharlotteDunois\Yasmin\Models\User|string $user Defaults to the client user.
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException | [
"Removes",
"an",
"user",
"from",
"the",
"reaction",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageReaction.php#L118-L130 |
CharlotteDunois/Yasmin | src/Models/RoleStorage.php | RoleStorage.resolve | function resolve($role) {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
return $role;
}
if(\is_int($role)) {
$role = (string) $role;
}
if(\is_string($role) && parent::has($role)) {
return parent::get($role);
}
throw new \InvalidArgumentException('Unable to resolve unknown role');
} | php | function resolve($role) {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
return $role;
}
if(\is_int($role)) {
$role = (string) $role;
}
if(\is_string($role) && parent::has($role)) {
return parent::get($role);
}
throw new \InvalidArgumentException('Unable to resolve unknown role');
} | [
"function",
"resolve",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"Role",
")",
"{",
"return",
"$",
"role",
";",
"}",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"role",
... | Resolves given data to a Role.
@param \CharlotteDunois\Yasmin\Models\Role|string|int $role string/int = role ID
@return \CharlotteDunois\Yasmin\Models\Role
@throws \InvalidArgumentException | [
"Resolves",
"given",
"data",
"to",
"a",
"Role",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/RoleStorage.php#L38-L52 |
CharlotteDunois/Yasmin | src/Models/RoleStorage.php | RoleStorage.factory | function factory(array $data) {
if(parent::has($data['id'])) {
$role = parent::get($data['id']);
$role->_patch($data);
return $role;
}
$role = new \CharlotteDunois\Yasmin\Models\Role($this->client, $this->guild, $data);
$this->set($role->id, $role);
return $role;
} | php | function factory(array $data) {
if(parent::has($data['id'])) {
$role = parent::get($data['id']);
$role->_patch($data);
return $role;
}
$role = new \CharlotteDunois\Yasmin\Models\Role($this->client, $this->guild, $data);
$this->set($role->id, $role);
return $role;
} | [
"function",
"factory",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"parent",
"::",
"has",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"role",
"=",
"parent",
"::",
"get",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"$",
"role... | Factory to create (or retrieve existing) roles.
@param array $data
@return \CharlotteDunois\Yasmin\Models\Role
@internal | [
"Factory",
"to",
"create",
"(",
"or",
"retrieve",
"existing",
")",
"roles",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/RoleStorage.php#L99-L109 |
CharlotteDunois/Yasmin | src/Utils/FileHelpers.php | FileHelpers.setLoop | static function setLoop(\React\EventLoop\LoopInterface $loop) {
self::$loop = $loop;
if(self::$filesystem === null) {
$adapters = \React\Filesystem\Filesystem::getSupportedAdapters();
if(!empty($adapters)) {
self::$filesystem = \React\Filesystem\Filesystem::create($loop);
}
}
} | php | static function setLoop(\React\EventLoop\LoopInterface $loop) {
self::$loop = $loop;
if(self::$filesystem === null) {
$adapters = \React\Filesystem\Filesystem::getSupportedAdapters();
if(!empty($adapters)) {
self::$filesystem = \React\Filesystem\Filesystem::create($loop);
}
}
} | [
"static",
"function",
"setLoop",
"(",
"\\",
"React",
"\\",
"EventLoop",
"\\",
"LoopInterface",
"$",
"loop",
")",
"{",
"self",
"::",
"$",
"loop",
"=",
"$",
"loop",
";",
"if",
"(",
"self",
"::",
"$",
"filesystem",
"===",
"null",
")",
"{",
"$",
"adapter... | Sets the Event Loop.
@param \React\EventLoop\LoopInterface $loop
@return void
@internal | [
"Sets",
"the",
"Event",
"Loop",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/FileHelpers.php#L32-L41 |
CharlotteDunois/Yasmin | src/Utils/FileHelpers.php | FileHelpers.setFilesystem | static function setFilesystem(?\React\Filesystem\FilesystemInterface $filesystem) {
if($filesystem === null) {
$filesystem = false;
}
self::$filesystem = $filesystem;
} | php | static function setFilesystem(?\React\Filesystem\FilesystemInterface $filesystem) {
if($filesystem === null) {
$filesystem = false;
}
self::$filesystem = $filesystem;
} | [
"static",
"function",
"setFilesystem",
"(",
"?",
"\\",
"React",
"\\",
"Filesystem",
"\\",
"FilesystemInterface",
"$",
"filesystem",
")",
"{",
"if",
"(",
"$",
"filesystem",
"===",
"null",
")",
"{",
"$",
"filesystem",
"=",
"false",
";",
"}",
"self",
"::",
... | Sets the React Filesystem instance, or disables it.
@param \React\Filesystem\FilesystemInterface|null $filesystem
@return void | [
"Sets",
"the",
"React",
"Filesystem",
"instance",
"or",
"disables",
"it",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/FileHelpers.php#L56-L62 |
CharlotteDunois/Yasmin | src/Utils/FileHelpers.php | FileHelpers.resolveFileResolvable | static function resolveFileResolvable(string $file) {
$rfile = @\realpath($file);
if($rfile) {
if(self::$filesystem) {
return self::$filesystem->getContents($file);
}
return \React\Promise\resolve(\file_get_contents($rfile));
} elseif(\filter_var($file, FILTER_VALIDATE_URL)) {
return \CharlotteDunois\Yasmin\Utils\URLHelpers::resolveURLToData($file);
}
return \React\Promise\reject(new \RuntimeException('Given file is not resolvable'));
} | php | static function resolveFileResolvable(string $file) {
$rfile = @\realpath($file);
if($rfile) {
if(self::$filesystem) {
return self::$filesystem->getContents($file);
}
return \React\Promise\resolve(\file_get_contents($rfile));
} elseif(\filter_var($file, FILTER_VALIDATE_URL)) {
return \CharlotteDunois\Yasmin\Utils\URLHelpers::resolveURLToData($file);
}
return \React\Promise\reject(new \RuntimeException('Given file is not resolvable'));
} | [
"static",
"function",
"resolveFileResolvable",
"(",
"string",
"$",
"file",
")",
"{",
"$",
"rfile",
"=",
"@",
"\\",
"realpath",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"rfile",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"filesystem",
")",
"{",
"ret... | Resolves filepath and URL into file data - returns it if it's neither. Resolves with a string.
@param string $file
@return \React\Promise\ExtendedPromiseInterface | [
"Resolves",
"filepath",
"and",
"URL",
"into",
"file",
"data",
"-",
"returns",
"it",
"if",
"it",
"s",
"neither",
".",
"Resolves",
"with",
"a",
"string",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Utils/FileHelpers.php#L69-L82 |
CharlotteDunois/Yasmin | src/WebSocket/WSManager.php | WSManager.connectShard | function connectShard(int $shardID, ?string $gateway = null, array $querystring = array()) {
if(!$gateway && !$this->gateway) {
throw new \RuntimeException('Unable to connect to unknown gateway for shard '.$shardID);
}
if(empty($this->client->token)) {
throw new \LogicException('No client token to start with');
}
if(($this->lastIdentify ?? 0) > (\time() - 5)) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($shardID, $gateway, $querystring) {
$this->client->addTimer((5 - (\time() - $this->lastIdentify)), function () use ($shardID, $gateway, $querystring, $resolve, $reject) {
$this->connectShard($shardID, $gateway, $querystring)->done($resolve, $reject);
});
}));
}
$reconnect = false;
if($this->gateway && (!$gateway || $this->gateway === $gateway)) {
if(!$gateway) {
$gateway = $this->gateway;
}
if(($this->lastIdentify ?? 0) > (\time() - 30)) { // Make sure we reconnect after at least 30 seconds, if there was like an outage, to prevent spamming
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($shardID, $gateway, $querystring) {
$time = (30 - (\time() - $this->lastIdentify));
$this->client->emit('debug', 'Reconnect for shard '.$shardID.' will be attempted in '.$time.' seconds');
$this->client->addTimer($time, function () use ($shardID, $gateway, $querystring, $resolve, $reject) {
$this->connectShard($shardID, $gateway, $querystring)->done($resolve, $reject);
});
}));
}
$shard = $this->client->shards->get($shardID);
if($shard !== null) {
$this->client->emit('reconnect', $shard);
}
$reconnect = true;
}
$this->handleConnectEncoding($querystring);
$this->createConnection($shardID);
$this->gateway = $this->handleConnectGateway($gateway, $querystring);
return $this->connections[$shardID]->connect($reconnect);
} | php | function connectShard(int $shardID, ?string $gateway = null, array $querystring = array()) {
if(!$gateway && !$this->gateway) {
throw new \RuntimeException('Unable to connect to unknown gateway for shard '.$shardID);
}
if(empty($this->client->token)) {
throw new \LogicException('No client token to start with');
}
if(($this->lastIdentify ?? 0) > (\time() - 5)) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($shardID, $gateway, $querystring) {
$this->client->addTimer((5 - (\time() - $this->lastIdentify)), function () use ($shardID, $gateway, $querystring, $resolve, $reject) {
$this->connectShard($shardID, $gateway, $querystring)->done($resolve, $reject);
});
}));
}
$reconnect = false;
if($this->gateway && (!$gateway || $this->gateway === $gateway)) {
if(!$gateway) {
$gateway = $this->gateway;
}
if(($this->lastIdentify ?? 0) > (\time() - 30)) { // Make sure we reconnect after at least 30 seconds, if there was like an outage, to prevent spamming
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($shardID, $gateway, $querystring) {
$time = (30 - (\time() - $this->lastIdentify));
$this->client->emit('debug', 'Reconnect for shard '.$shardID.' will be attempted in '.$time.' seconds');
$this->client->addTimer($time, function () use ($shardID, $gateway, $querystring, $resolve, $reject) {
$this->connectShard($shardID, $gateway, $querystring)->done($resolve, $reject);
});
}));
}
$shard = $this->client->shards->get($shardID);
if($shard !== null) {
$this->client->emit('reconnect', $shard);
}
$reconnect = true;
}
$this->handleConnectEncoding($querystring);
$this->createConnection($shardID);
$this->gateway = $this->handleConnectGateway($gateway, $querystring);
return $this->connections[$shardID]->connect($reconnect);
} | [
"function",
"connectShard",
"(",
"int",
"$",
"shardID",
",",
"?",
"string",
"$",
"gateway",
"=",
"null",
",",
"array",
"$",
"querystring",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"gateway",
"&&",
"!",
"$",
"this",
"->",
"gateway",
")... | Connects the specified shard to the gateway url. Resolves with an instance of WSConnection.
@return \React\Promise\ExtendedPromiseInterface
@throws \RuntimeException
@throws \LogicException
@see \CharlotteDunois\Yasmin\WebSocket\WSConnection | [
"Connects",
"the",
"specified",
"shard",
"to",
"the",
"gateway",
"url",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"WSConnection",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/WSManager.php#L246-L293 |
CharlotteDunois/Yasmin | src/WebSocket/WSManager.php | WSManager.createConnection | protected function createConnection(int $shardID) {
if(empty($this->connections[$shardID])) {
$this->connections[$shardID] = new \CharlotteDunois\Yasmin\WebSocket\WSConnection($this, $shardID, $this->compression);
$this->connections[$shardID]->on('close', function (int $code, string $reason) use ($shardID) {
$this->client->emit('debug', 'Shard '.$shardID.' disconnected with code '.$code.' and reason "'.$reason.'"');
$shard = $this->client->shards->get($shardID);
if($shard !== null) {
$this->client->emit('disconnect', $shard, $code, $reason);
}
});
}
} | php | protected function createConnection(int $shardID) {
if(empty($this->connections[$shardID])) {
$this->connections[$shardID] = new \CharlotteDunois\Yasmin\WebSocket\WSConnection($this, $shardID, $this->compression);
$this->connections[$shardID]->on('close', function (int $code, string $reason) use ($shardID) {
$this->client->emit('debug', 'Shard '.$shardID.' disconnected with code '.$code.' and reason "'.$reason.'"');
$shard = $this->client->shards->get($shardID);
if($shard !== null) {
$this->client->emit('disconnect', $shard, $code, $reason);
}
});
}
} | [
"protected",
"function",
"createConnection",
"(",
"int",
"$",
"shardID",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"connections",
"[",
"$",
"shardID",
"]",
")",
")",
"{",
"$",
"this",
"->",
"connections",
"[",
"$",
"shardID",
"]",
"=",
"n... | Creates a new ws connection for a specific shard, if necessary.
@param int $shardID
@return void | [
"Creates",
"a",
"new",
"ws",
"connection",
"for",
"a",
"specific",
"shard",
"if",
"necessary",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/WSManager.php#L309-L322 |
CharlotteDunois/Yasmin | src/WebSocket/WSManager.php | WSManager.handleConnectEncoding | protected function handleConnectEncoding(array &$querystring) {
if($this->encoding === null) {
$encoding = $querystring['encoding'] ?? self::WS['encoding'];
$name = \str_replace('-', '', \ucwords($encoding, '-'));
if(\strpos($name, '\\') === false) {
$name = '\\CharlotteDunois\\Yasmin\\WebSocket\\Encoding\\'.$name;
}
$name::supported();
$interfaces = \class_implements($name);
if(!\in_array('CharlotteDunois\\Yasmin\\Interfaces\\WSEncodingInterface', $interfaces)) {
throw new \RuntimeException('Specified WS encoding class does not implement necessary interface');
}
$this->encoding = new $name();
$querystring['encoding'] = $this->encoding->getName();
}
} | php | protected function handleConnectEncoding(array &$querystring) {
if($this->encoding === null) {
$encoding = $querystring['encoding'] ?? self::WS['encoding'];
$name = \str_replace('-', '', \ucwords($encoding, '-'));
if(\strpos($name, '\\') === false) {
$name = '\\CharlotteDunois\\Yasmin\\WebSocket\\Encoding\\'.$name;
}
$name::supported();
$interfaces = \class_implements($name);
if(!\in_array('CharlotteDunois\\Yasmin\\Interfaces\\WSEncodingInterface', $interfaces)) {
throw new \RuntimeException('Specified WS encoding class does not implement necessary interface');
}
$this->encoding = new $name();
$querystring['encoding'] = $this->encoding->getName();
}
} | [
"protected",
"function",
"handleConnectEncoding",
"(",
"array",
"&",
"$",
"querystring",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"querystring",
"[",
"'encoding'",
"]",
"??",
"self",
"::",
"W... | Handles the connect encoding for the query string.
@param array $querystring
@return void
@throws \RuntimeException | [
"Handles",
"the",
"connect",
"encoding",
"for",
"the",
"query",
"string",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/WSManager.php#L330-L349 |
CharlotteDunois/Yasmin | src/WebSocket/WSManager.php | WSManager.handleConnectGateway | protected function handleConnectGateway(string $gateway, array &$querystring) {
if(!empty($querystring)) {
if($this->compression !== '') {
$compression = $this->compression;
$querystring['compress'] = $compression::getName();
}
$this->gatewayQS = $querystring;
$gateway = \rtrim($gateway, '/').'/?'.\http_build_query($querystring);
}
return $gateway;
} | php | protected function handleConnectGateway(string $gateway, array &$querystring) {
if(!empty($querystring)) {
if($this->compression !== '') {
$compression = $this->compression;
$querystring['compress'] = $compression::getName();
}
$this->gatewayQS = $querystring;
$gateway = \rtrim($gateway, '/').'/?'.\http_build_query($querystring);
}
return $gateway;
} | [
"protected",
"function",
"handleConnectGateway",
"(",
"string",
"$",
"gateway",
",",
"array",
"&",
"$",
"querystring",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"querystring",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"compression",
"!==",
"''",
... | Handles the connect gateway URL in terms to the query string..
@param string $gateway
@param array $querystring
@return string
@throws \RuntimeException | [
"Handles",
"the",
"connect",
"gateway",
"URL",
"in",
"terms",
"to",
"the",
"query",
"string",
".."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/WSManager.php#L358-L370 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.clearReactions | function clearReactions() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->deleteMessageReactions($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function clearReactions() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->deleteMessageReactions($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"clearReactions",
"(",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"apimanager... | Removes all reactions from the message. Resolves with $this.
@return \React\Promise\ExtendedPromiseInterface | [
"Removes",
"all",
"reactions",
"from",
"the",
"message",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L265-L271 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.collectReactions | function collectReactions(callable $filter, array $options = array()) {
$rhandler = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) {
return array(($reaction->emoji->id ?? $reaction->emoji->name), array($reaction, $user));
};
$rfilter = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) use ($filter) {
return ($this->id === $reaction->message->id && $filter($reaction, $user));
};
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($this->client, 'messageReactionAdd', $rhandler, $rfilter, $options);
return $collector->collect();
} | php | function collectReactions(callable $filter, array $options = array()) {
$rhandler = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) {
return array(($reaction->emoji->id ?? $reaction->emoji->name), array($reaction, $user));
};
$rfilter = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) use ($filter) {
return ($this->id === $reaction->message->id && $filter($reaction, $user));
};
$collector = new \CharlotteDunois\Yasmin\Utils\Collector($this->client, 'messageReactionAdd', $rhandler, $rfilter, $options);
return $collector->collect();
} | [
"function",
"collectReactions",
"(",
"callable",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"rhandler",
"=",
"function",
"(",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"MessageReaction",
"$",
"r... | Collects reactions during a specific duration. Resolves with a Collection of `[ $messageReaction, $user ]` arrays, mapped by their IDs or names (unicode emojis).
Options are as following:
```
array(
'max' => int, (max. message reactions to collect)
'time' => int, (duration, in seconds, default 30)
'errors' => array, (optional, which failed "conditions" (max not reached in time ("time")) lead to a rejected promise, defaults to [])
)
```
@param callable $filter The filter to only collect desired reactions. Signature: `function (MessageReaction $messageReaction, User $user): bool`
@param array $options The collector options.
@return \React\Promise\ExtendedPromiseInterface This promise is cancellable.
@throws \RangeException The exception the promise gets rejected with, if collecting times out.
@throws \OutOfBoundsException The exception the promise gets rejected with, if the promise gets cancelled.
@see \CharlotteDunois\Yasmin\Models\MessageReaction
@see \CharlotteDunois\Yasmin\Models\User
@see \CharlotteDunois\Yasmin\Utils\Collector | [
"Collects",
"reactions",
"during",
"a",
"specific",
"duration",
".",
"Resolves",
"with",
"a",
"Collection",
"of",
"[",
"$messageReaction",
"$user",
"]",
"arrays",
"mapped",
"by",
"their",
"IDs",
"or",
"names",
"(",
"unicode",
"emojis",
")",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L295-L305 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.edit | function edit(?string $content, array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($content, $options) {
$msg = array();
if($content !== null) {
$msg['content'] = $content;
}
if(\array_key_exists('embed', $options)) {
$msg['embed'] = $options['embed'];
}
$this->client->apimanager()->endpoints->channel->editMessage($this->channel->getId(), $this->id, $msg)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function edit(?string $content, array $options = array()) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($content, $options) {
$msg = array();
if($content !== null) {
$msg['content'] = $content;
}
if(\array_key_exists('embed', $options)) {
$msg['embed'] = $options['embed'];
}
$this->client->apimanager()->endpoints->channel->editMessage($this->channel->getId(), $this->id, $msg)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"edit",
"(",
"?",
"string",
"$",
"content",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"cal... | Edits the message. You need to be the author of the message. Resolves with $this.
@param string|null $content The message contents.
@param array $options An array with options. Only embed is supported by edit.
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Traits\TextChannelTrait::send() | [
"Edits",
"the",
"message",
".",
"You",
"need",
"to",
"be",
"the",
"author",
"of",
"the",
"message",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L314-L330 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.delete | function delete($timeout = 0, string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($timeout, $reason) {
if($timeout > 0) {
$this->client->addTimer($timeout, function () use ($reason, $resolve, $reject) {
$this->delete(0, $reason)->done($resolve, $reject);
});
} else {
$this->client->apimanager()->endpoints->channel->deleteMessage($this->channel->getId(), $this->id, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}
}));
} | php | function delete($timeout = 0, string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($timeout, $reason) {
if($timeout > 0) {
$this->client->addTimer($timeout, function () use ($reason, $resolve, $reject) {
$this->delete(0, $reason)->done($resolve, $reject);
});
} else {
$this->client->apimanager()->endpoints->channel->deleteMessage($this->channel->getId(), $this->id, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}
}));
} | [
"function",
"delete",
"(",
"$",
"timeout",
"=",
"0",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"re... | Deletes the message.
@param float|int $timeout An integer or float as timeout in seconds, after which the message gets deleted.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Deletes",
"the",
"message",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L338-L350 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.fetchWebhook | function fetchWebhook() {
if($this->webhookID === null) {
throw new \BadMethodCallException('Unable to fetch webhook from a message that was not posted by a webhook');
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->webhook->getWebhook($this->webhookID)->done(function ($data) use ($resolve) {
$webhook = new \CharlotteDunois\Yasmin\Models\Webhook($this->client, $data);
$resolve($webhook);
}, $reject);
}));
} | php | function fetchWebhook() {
if($this->webhookID === null) {
throw new \BadMethodCallException('Unable to fetch webhook from a message that was not posted by a webhook');
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->webhook->getWebhook($this->webhookID)->done(function ($data) use ($resolve) {
$webhook = new \CharlotteDunois\Yasmin\Models\Webhook($this->client, $data);
$resolve($webhook);
}, $reject);
}));
} | [
"function",
"fetchWebhook",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"webhookID",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'Unable to fetch webhook from a message that was not posted by a webhook'",
")",
";",
"}",
"return",
... | Fetches the webhook used to create this message. Resolves with an instance of Webhook.
@return \React\Promise\ExtendedPromiseInterface
@throws \BadMethodCallException
@see \CharlotteDunois\Yasmin\Models\Webhook | [
"Fetches",
"the",
"webhook",
"used",
"to",
"create",
"this",
"message",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"Webhook",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L358-L369 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.getJumpURL | function getJumpURL() {
$guild = ($this->channel instanceof \CharlotteDunois\Yasmin\Models\TextChannel ? $this->guild->id : '@me');
return 'https://canary.discordapp.com/channels/'.$guild.'/'.$this->channel->getId().'/'.$this->id;
} | php | function getJumpURL() {
$guild = ($this->channel instanceof \CharlotteDunois\Yasmin\Models\TextChannel ? $this->guild->id : '@me');
return 'https://canary.discordapp.com/channels/'.$guild.'/'.$this->channel->getId().'/'.$this->id;
} | [
"function",
"getJumpURL",
"(",
")",
"{",
"$",
"guild",
"=",
"(",
"$",
"this",
"->",
"channel",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"TextChannel",
"?",
"$",
"this",
"->",
"guild",
"->",
"id",
":",
"'@me'",
")",
"... | Returns the jump to message link for this message.
@return string | [
"Returns",
"the",
"jump",
"to",
"message",
"link",
"for",
"this",
"message",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L375-L378 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.pin | function pin() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->pinChannelMessage($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function pin() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->pinChannelMessage($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"pin",
"(",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"apimanager",
"(",
... | Pins the message. Resolves with $this.
@return \React\Promise\ExtendedPromiseInterface | [
"Pins",
"the",
"message",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L384-L390 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.react | function react($emoji) {
try {
$emoji = $this->client->emojis->resolve($emoji);
} catch (\InvalidArgumentException $e) {
if(\is_numeric($emoji)) {
throw $e;
}
$match = (bool) \preg_match('/(?:<a?:)?(.+):(\d+)/', $emoji, $matches);
if($match) {
$emoji = $matches[1].':'.$matches[2];
} else {
$emoji = \rawurlencode($emoji);
}
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($emoji) {
if($emoji instanceof \CharlotteDunois\Yasmin\Models\Emoji) {
$emoji = $emoji->identifier;
}
$filter = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) use ($emoji) {
return ($user->id === $this->client->user->id && $reaction->message->id === $this->id && $reaction->emoji->identifier === $emoji);
};
$prom = \CharlotteDunois\Yasmin\Utils\EventHelpers::waitForEvent($this->client, 'messageReactionAdd', $filter, array('time' => 30))->then(function ($args) use ($resolve) {
$resolve($args[0]);
}, function ($error) use ($reject) {
if($error instanceof \RangeException) {
$reject(new \RangeException('Message Reaction did not arrive in time'));
} elseif(!($error instanceof \OutOfBoundsException)) {
$reject($error);
}
});
$this->client->apimanager()->endpoints->channel->createMessageReaction($this->channel->getId(), $this->id, $emoji)->done(null, function ($error) use ($prom, $reject) {
$prom->cancel();
$reject($error);
});
}));
} | php | function react($emoji) {
try {
$emoji = $this->client->emojis->resolve($emoji);
} catch (\InvalidArgumentException $e) {
if(\is_numeric($emoji)) {
throw $e;
}
$match = (bool) \preg_match('/(?:<a?:)?(.+):(\d+)/', $emoji, $matches);
if($match) {
$emoji = $matches[1].':'.$matches[2];
} else {
$emoji = \rawurlencode($emoji);
}
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($emoji) {
if($emoji instanceof \CharlotteDunois\Yasmin\Models\Emoji) {
$emoji = $emoji->identifier;
}
$filter = function (\CharlotteDunois\Yasmin\Models\MessageReaction $reaction, \CharlotteDunois\Yasmin\Models\User $user) use ($emoji) {
return ($user->id === $this->client->user->id && $reaction->message->id === $this->id && $reaction->emoji->identifier === $emoji);
};
$prom = \CharlotteDunois\Yasmin\Utils\EventHelpers::waitForEvent($this->client, 'messageReactionAdd', $filter, array('time' => 30))->then(function ($args) use ($resolve) {
$resolve($args[0]);
}, function ($error) use ($reject) {
if($error instanceof \RangeException) {
$reject(new \RangeException('Message Reaction did not arrive in time'));
} elseif(!($error instanceof \OutOfBoundsException)) {
$reject($error);
}
});
$this->client->apimanager()->endpoints->channel->createMessageReaction($this->channel->getId(), $this->id, $emoji)->done(null, function ($error) use ($prom, $reject) {
$prom->cancel();
$reject($error);
});
}));
} | [
"function",
"react",
"(",
"$",
"emoji",
")",
"{",
"try",
"{",
"$",
"emoji",
"=",
"$",
"this",
"->",
"client",
"->",
"emojis",
"->",
"resolve",
"(",
"$",
"emoji",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"if... | Reacts to the message with the specified unicode or custom emoji. Resolves with an instance of MessageReaction.
@param \CharlotteDunois\Yasmin\Models\Emoji|\CharlotteDunois\Yasmin\Models\MessageReaction|string $emoji
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException
@see \CharlotteDunois\Yasmin\Models\MessageReaction | [
"Reacts",
"to",
"the",
"message",
"with",
"the",
"specified",
"unicode",
"or",
"custom",
"emoji",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"MessageReaction",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L399-L439 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.reply | function reply(string $content, array $options = array()) {
return $this->channel->send($this->author->__toString().self::$replySeparator.$content, $options);
} | php | function reply(string $content, array $options = array()) {
return $this->channel->send($this->author->__toString().self::$replySeparator.$content, $options);
} | [
"function",
"reply",
"(",
"string",
"$",
"content",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"channel",
"->",
"send",
"(",
"$",
"this",
"->",
"author",
"->",
"__toString",
"(",
")",
".",
"self",
"... | Replies to the message. Resolves with an instance of Message, or with a Collection of Message instances, mapped by their ID.
@param string $content
@param array $options
@return \React\Promise\ExtendedPromiseInterface
@see \CharlotteDunois\Yasmin\Traits\TextChannelTrait::send() | [
"Replies",
"to",
"the",
"message",
".",
"Resolves",
"with",
"an",
"instance",
"of",
"Message",
"or",
"with",
"a",
"Collection",
"of",
"Message",
"instances",
"mapped",
"by",
"their",
"ID",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L448-L450 |
CharlotteDunois/Yasmin | src/Models/Message.php | Message.unpin | function unpin() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->unpinChannelMessage($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function unpin() {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) {
$this->client->apimanager()->endpoints->channel->unpinChannelMessage($this->channel->getId(), $this->id)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"unpin",
"(",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"apimanager",
"(",... | Unpins the message. Resolves with $this.
@return \React\Promise\ExtendedPromiseInterface | [
"Unpins",
"the",
"message",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Message.php#L456-L462 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Etf.php | Etf.decode | function decode(string $data) {
try {
$msg = $this->etf->decode($data);
if($msg === '' || $msg === null) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF decoder was unable to decode the data');
}
} catch (\CharlotteDunois\Kimberly\Exception $e) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF decoder was unable to decode the data', 0, $e);
}
$obj = $this->convertIDs($msg);
return $obj;
} | php | function decode(string $data) {
try {
$msg = $this->etf->decode($data);
if($msg === '' || $msg === null) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF decoder was unable to decode the data');
}
} catch (\CharlotteDunois\Kimberly\Exception $e) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF decoder was unable to decode the data', 0, $e);
}
$obj = $this->convertIDs($msg);
return $obj;
} | [
"function",
"decode",
"(",
"string",
"$",
"data",
")",
"{",
"try",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"etf",
"->",
"decode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"msg",
"===",
"''",
"||",
"$",
"msg",
"===",
"null",
")",
"{",
"thr... | Decodes data.
@param string $data
@return mixed
@throws \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException | [
"Decodes",
"data",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Etf.php#L58-L70 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Etf.php | Etf.encode | function encode($data): string {
try {
return $this->etf->encode($data);
} catch (\CharlotteDunois\Kimberly\Exception $e) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF encoder was unable to encode the data', 0, $e);
}
} | php | function encode($data): string {
try {
return $this->etf->encode($data);
} catch (\CharlotteDunois\Kimberly\Exception $e) {
throw new \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException('The ETF encoder was unable to encode the data', 0, $e);
}
} | [
"function",
"encode",
"(",
"$",
"data",
")",
":",
"string",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"etf",
"->",
"encode",
"(",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"CharlotteDunois",
"\\",
"Kimberly",
"\\",
"Exception",
"$",
"e",
... | Encodes data.
@param mixed $data
@return string
@throws \CharlotteDunois\Yasmin\WebSocket\DiscordGatewayException | [
"Encodes",
"data",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Etf.php#L78-L84 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Etf.php | Etf.prepareMessage | function prepareMessage(string $data): \Ratchet\RFC6455\Messaging\Message {
$frame = new \Ratchet\RFC6455\Messaging\Frame($data, true, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
$msg = new \Ratchet\RFC6455\Messaging\Message();
$msg->addFrame($frame);
return $msg;
} | php | function prepareMessage(string $data): \Ratchet\RFC6455\Messaging\Message {
$frame = new \Ratchet\RFC6455\Messaging\Frame($data, true, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
$msg = new \Ratchet\RFC6455\Messaging\Message();
$msg->addFrame($frame);
return $msg;
} | [
"function",
"prepareMessage",
"(",
"string",
"$",
"data",
")",
":",
"\\",
"Ratchet",
"\\",
"RFC6455",
"\\",
"Messaging",
"\\",
"Message",
"{",
"$",
"frame",
"=",
"new",
"\\",
"Ratchet",
"\\",
"RFC6455",
"\\",
"Messaging",
"\\",
"Frame",
"(",
"$",
"data",... | Prepares the data to be sent.
@param string $data
@return \Ratchet\RFC6455\Messaging\Message | [
"Prepares",
"the",
"data",
"to",
"be",
"sent",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Etf.php#L91-L98 |
CharlotteDunois/Yasmin | src/WebSocket/Encoding/Etf.php | Etf.convertIDs | protected function convertIDs($data) {
$arr = array();
foreach($data as $key => $val) {
if(\is_string($key) && $key[0] === ':') {
$key = \mb_substr($key, 1);
}
if($val instanceof \CharlotteDunois\Kimberly\Atom) {
$arr[$key] = (string) $val->atom;
} elseif($val instanceof \CharlotteDunois\Kimberly\BaseObject) {
$arr[$key] = $val->toArray();
} elseif(\is_array($val) || \is_object($val)) {
$arr[$key] = $this->convertIDs($val);
} else {
if(\is_int($val) && ($key === 'id' || \mb_substr($key, -3) === '_id')) {
$val = (string) $val;
}
$arr[$key] = $val;
}
}
return (\is_object($data) ? ((object) $arr) : $arr);
} | php | protected function convertIDs($data) {
$arr = array();
foreach($data as $key => $val) {
if(\is_string($key) && $key[0] === ':') {
$key = \mb_substr($key, 1);
}
if($val instanceof \CharlotteDunois\Kimberly\Atom) {
$arr[$key] = (string) $val->atom;
} elseif($val instanceof \CharlotteDunois\Kimberly\BaseObject) {
$arr[$key] = $val->toArray();
} elseif(\is_array($val) || \is_object($val)) {
$arr[$key] = $this->convertIDs($val);
} else {
if(\is_int($val) && ($key === 'id' || \mb_substr($key, -3) === '_id')) {
$val = (string) $val;
}
$arr[$key] = $val;
}
}
return (\is_object($data) ? ((object) $arr) : $arr);
} | [
"protected",
"function",
"convertIDs",
"(",
"$",
"data",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"key",
")",
"&&",
"$"... | Converts all IDs from integer to strings.
@param array|object $data
@return array|object | [
"Converts",
"all",
"IDs",
"from",
"integer",
"to",
"strings",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/WebSocket/Encoding/Etf.php#L105-L129 |
CharlotteDunois/Yasmin | src/Models/Activity.php | Activity.isRichPresence | function isRichPresence() {
return ($this->applicationID !== null || $this->party !== null || $this->sessionID !== null || $this->syncID !== null);
} | php | function isRichPresence() {
return ($this->applicationID !== null || $this->party !== null || $this->sessionID !== null || $this->syncID !== null);
} | [
"function",
"isRichPresence",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"applicationID",
"!==",
"null",
"||",
"$",
"this",
"->",
"party",
"!==",
"null",
"||",
"$",
"this",
"->",
"sessionID",
"!==",
"null",
"||",
"$",
"this",
"->",
"syncID",
"!==... | Whether this activity is a rich presence.
@return bool | [
"Whether",
"this",
"activity",
"is",
"a",
"rich",
"presence",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Activity.php#L190-L192 |
CharlotteDunois/Yasmin | src/Models/MessageStorage.php | MessageStorage.set | function set($key, $value) {
if(!$this->enabled) {
return $this;
}
parent::set($key, $value);
return $this;
} | php | function set($key, $value) {
if(!$this->enabled) {
return $this;
}
parent::set($key, $value);
return $this;
} | [
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"{",
"return",
"$",
"this",
";",
"}",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"thi... | {@inheritdoc}
@param string $key
@param \CharlotteDunois\Yasmin\Models\Message $value
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageStorage.php#L89-L96 |
CharlotteDunois/Yasmin | src/Models/MessageStorage.php | MessageStorage.sweep | function sweep(int $time) {
if($time <= 0) {
$this->clear();
return;
}
$amount = 0;
foreach($this->data as $key => $msg) {
if($msg->createdTimestamp > (\time() - $time)) {
$this->delete($msg->id);
unset($msg);
$amount++;
}
}
return $amount;
} | php | function sweep(int $time) {
if($time <= 0) {
$this->clear();
return;
}
$amount = 0;
foreach($this->data as $key => $msg) {
if($msg->createdTimestamp > (\time() - $time)) {
$this->delete($msg->id);
unset($msg);
$amount++;
}
}
return $amount;
} | [
"function",
"sweep",
"(",
"int",
"$",
"time",
")",
"{",
"if",
"(",
"$",
"time",
"<=",
"0",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
";",
"}",
"$",
"amount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",... | Sweeps messages, deletes messages older than the parameter (timestamp - $time). Returns the amount of sweeped messages.
@param int $time 0 = clear all
@return int | [
"Sweeps",
"messages",
"deletes",
"messages",
"older",
"than",
"the",
"parameter",
"(",
"timestamp",
"-",
"$time",
")",
".",
"Returns",
"the",
"amount",
"of",
"sweeped",
"messages",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/MessageStorage.php#L113-L130 |
CharlotteDunois/Yasmin | src/Models/EmojiStorage.php | EmojiStorage.resolve | function resolve($emoji) {
if($emoji instanceof \CharlotteDunois\Yasmin\Models\Emoji) {
return $emoji;
}
if($emoji instanceof \CharlotteDunois\Yasmin\Models\MessageReaction) {
return $emoji->emoji;
}
if(\is_int($emoji)) {
$emoji = (string) $emoji;
}
if(\is_string($emoji) && parent::has($emoji)) {
return parent::get($emoji);
}
throw new \InvalidArgumentException('Unable to resolve unknown emoji');
} | php | function resolve($emoji) {
if($emoji instanceof \CharlotteDunois\Yasmin\Models\Emoji) {
return $emoji;
}
if($emoji instanceof \CharlotteDunois\Yasmin\Models\MessageReaction) {
return $emoji->emoji;
}
if(\is_int($emoji)) {
$emoji = (string) $emoji;
}
if(\is_string($emoji) && parent::has($emoji)) {
return parent::get($emoji);
}
throw new \InvalidArgumentException('Unable to resolve unknown emoji');
} | [
"function",
"resolve",
"(",
"$",
"emoji",
")",
"{",
"if",
"(",
"$",
"emoji",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"Emoji",
")",
"{",
"return",
"$",
"emoji",
";",
"}",
"if",
"(",
"$",
"emoji",
"instanceof",
"\\",
... | Resolves given data to an emoji.
@param \CharlotteDunois\Yasmin\Models\Emoji|\CharlotteDunois\Yasmin\Models\MessageReaction|string|int $emoji string/int = emoji ID
@return \CharlotteDunois\Yasmin\Models\Emoji
@throws \InvalidArgumentException | [
"Resolves",
"given",
"data",
"to",
"an",
"emoji",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/EmojiStorage.php#L38-L56 |
CharlotteDunois/Yasmin | src/Models/EmojiStorage.php | EmojiStorage.set | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->emojis) {
$this->client->emojis->set($key, $value);
}
return $this;
} | php | function set($key, $value) {
parent::set($key, $value);
if($this !== $this->client->emojis) {
$this->client->emojis->set($key, $value);
}
return $this;
} | [
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"emojis",
")",
"{",
"$",
"this",
"->",
"cl... | {@inheritdoc}
@param string $key
@param \CharlotteDunois\Yasmin\Models\Emoji $value
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/EmojiStorage.php#L82-L89 |
CharlotteDunois/Yasmin | src/Models/EmojiStorage.php | EmojiStorage.delete | function delete($key) {
parent::delete($key);
if($this !== $this->client->emojis) {
$this->client->emojis->delete($key);
}
return $this;
} | php | function delete($key) {
parent::delete($key);
if($this !== $this->client->emojis) {
$this->client->emojis->delete($key);
}
return $this;
} | [
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"parent",
"::",
"delete",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"!==",
"$",
"this",
"->",
"client",
"->",
"emojis",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"emojis",
"->",
"delete... | {@inheritdoc}
@param string $key
@return $this | [
"{"
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/EmojiStorage.php#L96-L103 |
CharlotteDunois/Yasmin | src/Models/EmojiStorage.php | EmojiStorage.factory | function factory(array $data) {
if(parent::has($data['id'])) {
$emoji = parent::get($data['id']);
$emoji->_patch($data);
return $emoji;
}
$emoji = new \CharlotteDunois\Yasmin\Models\Emoji($this->client, $this->guild, $data);
if($emoji->id !== null) {
$this->set($emoji->id, $emoji);
$this->client->emojis->set($emoji->id, $emoji);
}
return $emoji;
} | php | function factory(array $data) {
if(parent::has($data['id'])) {
$emoji = parent::get($data['id']);
$emoji->_patch($data);
return $emoji;
}
$emoji = new \CharlotteDunois\Yasmin\Models\Emoji($this->client, $this->guild, $data);
if($emoji->id !== null) {
$this->set($emoji->id, $emoji);
$this->client->emojis->set($emoji->id, $emoji);
}
return $emoji;
} | [
"function",
"factory",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"parent",
"::",
"has",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"emoji",
"=",
"parent",
"::",
"get",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"$",
"emo... | Factory to create (or retrieve existing) emojis.
@param array $data
@return \CharlotteDunois\Yasmin\Models\Emoji
@internal | [
"Factory",
"to",
"create",
"(",
"or",
"retrieve",
"existing",
")",
"emojis",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/EmojiStorage.php#L111-L126 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.addRoles | function addRoles($roles, string $reason = '') {
if($roles instanceof \CharlotteDunois\Collect\Collection) {
$roles = $roles->all();
}
$roles = \array_merge($this->roles->all(), $roles);
return $this->edit(array('roles' => $roles), $reason);
} | php | function addRoles($roles, string $reason = '') {
if($roles instanceof \CharlotteDunois\Collect\Collection) {
$roles = $roles->all();
}
$roles = \array_merge($this->roles->all(), $roles);
return $this->edit(array('roles' => $roles), $reason);
} | [
"function",
"addRoles",
"(",
"$",
"roles",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"roles",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Collect",
"\\",
"Collection",
")",
"{",
"$",
"roles",
"=",
"$",
"roles",
"->",
"all",
... | Adds roles to the guild member. Resolves with $this.
@param array|\CharlotteDunois\Collect\Collection $roles A collection or array of Role instances or role IDs.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Adds",
"roles",
"to",
"the",
"guild",
"member",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L192-L199 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.ban | function ban(int $days = 0, string $reason = '') {
return $this->guild->ban($this, $days, $reason);
} | php | function ban(int $days = 0, string $reason = '') {
return $this->guild->ban($this, $days, $reason);
} | [
"function",
"ban",
"(",
"int",
"$",
"days",
"=",
"0",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"guild",
"->",
"ban",
"(",
"$",
"this",
",",
"$",
"days",
",",
"$",
"reason",
")",
";",
"}"
] | Bans the guild member.
@param int $days Number of days of messages to delete (0-7).
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Bans",
"the",
"guild",
"member",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L207-L209 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.edit | function edit(array $options, string $reason = '') {
$data = \CharlotteDunois\Yasmin\Utils\DataHelpers::applyOptions($options, array(
'nick' => array('type' => 'string'),
'roles' => array('parse' => function ($val) {
if($val instanceof \CharlotteDunois\Collect\Collection) {
$val = $val->all();
}
return \array_unique(\array_map(function ($role) {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
return $role->id;
}
return $role;
}, $val));
}),
'deaf' => array('type' => 'bool'),
'mute' => array('type' => 'bool'),
'channel' => array('parse' => function ($val) {
return ($val !== null ? $this->guild->channels->resolve($val)->getId() : null);
})
));
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($data, $reason) {
$this->client->apimanager()->endpoints->guild->modifyGuildMember($this->guild->id, $this->id, $data, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function edit(array $options, string $reason = '') {
$data = \CharlotteDunois\Yasmin\Utils\DataHelpers::applyOptions($options, array(
'nick' => array('type' => 'string'),
'roles' => array('parse' => function ($val) {
if($val instanceof \CharlotteDunois\Collect\Collection) {
$val = $val->all();
}
return \array_unique(\array_map(function ($role) {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
return $role->id;
}
return $role;
}, $val));
}),
'deaf' => array('type' => 'bool'),
'mute' => array('type' => 'bool'),
'channel' => array('parse' => function ($val) {
return ($val !== null ? $this->guild->channels->resolve($val)->getId() : null);
})
));
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($data, $reason) {
$this->client->apimanager()->endpoints->guild->modifyGuildMember($this->guild->id, $this->id, $data, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"edit",
"(",
"array",
"$",
"options",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Utils",
"\\",
"DataHelpers",
"::",
"applyOptions",
"(",
"$",
"options",
",",
"array",
... | Edits the guild member. Resolves with $this.
Options are as following (only one required):
```
array(
'nick' => string,
'roles' => array|\CharlotteDunois\Collect\Collection, (of role instances or role IDs)
'deaf' => bool,
'mute' => bool,
'channel' => \CharlotteDunois\Yasmin\Models\VoiceChannel|string|null (will move the member to that channel, if member is connected to voice)
)
```
@param array $options
@param string $reason
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException | [
"Edits",
"the",
"guild",
"member",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L231-L259 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.getColorRole | function getColorRole() {
$roles = $this->roles->filter(function ($role) {
return $role->color;
});
if($roles->count() === 0) {
return null;
}
return $roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | php | function getColorRole() {
$roles = $this->roles->filter(function ($role) {
return $role->color;
});
if($roles->count() === 0) {
return null;
}
return $roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | [
"function",
"getColorRole",
"(",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
"->",
"filter",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"return",
"$",
"role",
"->",
"color",
";",
"}",
")",
";",
"if",
"(",
"$",
"roles",
"->",
"count... | Gets the role the member is displayed with.
@return \CharlotteDunois\Yasmin\Models\Role | [
"Gets",
"the",
"role",
"the",
"member",
"is",
"displayed",
"with",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L265-L281 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.getDisplayColor | function getDisplayColor() {
$colorRole = $this->getColorRole();
if($colorRole !== null && $colorRole->color > 0) {
return $colorRole->color;
}
return null;
} | php | function getDisplayColor() {
$colorRole = $this->getColorRole();
if($colorRole !== null && $colorRole->color > 0) {
return $colorRole->color;
}
return null;
} | [
"function",
"getDisplayColor",
"(",
")",
"{",
"$",
"colorRole",
"=",
"$",
"this",
"->",
"getColorRole",
"(",
")",
";",
"if",
"(",
"$",
"colorRole",
"!==",
"null",
"&&",
"$",
"colorRole",
"->",
"color",
">",
"0",
")",
"{",
"return",
"$",
"colorRole",
... | Gets the displayed color of the member.
@return int|null | [
"Gets",
"the",
"displayed",
"color",
"of",
"the",
"member",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L287-L294 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.getDisplayHexColor | function getDisplayHexColor() {
$colorRole = $this->getColorRole();
if($colorRole !== null && $colorRole->color > 0) {
return $colorRole->hexColor;
}
return null;
} | php | function getDisplayHexColor() {
$colorRole = $this->getColorRole();
if($colorRole !== null && $colorRole->color > 0) {
return $colorRole->hexColor;
}
return null;
} | [
"function",
"getDisplayHexColor",
"(",
")",
"{",
"$",
"colorRole",
"=",
"$",
"this",
"->",
"getColorRole",
"(",
")",
";",
"if",
"(",
"$",
"colorRole",
"!==",
"null",
"&&",
"$",
"colorRole",
"->",
"color",
">",
"0",
")",
"{",
"return",
"$",
"colorRole",... | Gets the displayed color of the member as hex string.
@return string|null | [
"Gets",
"the",
"displayed",
"color",
"of",
"the",
"member",
"as",
"hex",
"string",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L300-L307 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.getHighestRole | function getHighestRole() {
return $this->roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | php | function getHighestRole() {
return $this->roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | [
"function",
"getHighestRole",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"roles",
"->",
"reduce",
"(",
"function",
"(",
"$",
"prev",
",",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"prev",
"===",
"null",
")",
"{",
"return",
"$",
"role",
";",
"}",
"r... | Gets the highest role of the member.
@return \CharlotteDunois\Yasmin\Models\Role | [
"Gets",
"the",
"highest",
"role",
"of",
"the",
"member",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L313-L321 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.getHoistRole | function getHoistRole() {
$roles = $this->roles->filter(function ($role) {
return $role->hoist;
});
if($roles->count() === 0) {
return null;
}
return $roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | php | function getHoistRole() {
$roles = $this->roles->filter(function ($role) {
return $role->hoist;
});
if($roles->count() === 0) {
return null;
}
return $roles->reduce(function ($prev, $role) {
if($prev === null) {
return $role;
}
return ($role->comparePositionTo($prev) > 0 ? $role : $prev);
});
} | [
"function",
"getHoistRole",
"(",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
"->",
"filter",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"return",
"$",
"role",
"->",
"hoist",
";",
"}",
")",
";",
"if",
"(",
"$",
"roles",
"->",
"count... | Gets the role the member is hoisted with.
@return \CharlotteDunois\Yasmin\Models\Role|null | [
"Gets",
"the",
"role",
"the",
"member",
"is",
"hoisted",
"with",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L327-L343 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.isBannable | function isBannable() {
if($this->id === $this->guild->ownerID || $this->id === $this->client->user->id) {
return false;
}
$member = $this->guild->me;
if(!$member->permissions->has(\CharlotteDunois\Yasmin\Models\Permissions::PERMISSIONS['BAN_MEMBERS'])) {
return false;
}
return ($member->getHighestRole()->comparePositionTo($this->getHighestRole()) > 0);
} | php | function isBannable() {
if($this->id === $this->guild->ownerID || $this->id === $this->client->user->id) {
return false;
}
$member = $this->guild->me;
if(!$member->permissions->has(\CharlotteDunois\Yasmin\Models\Permissions::PERMISSIONS['BAN_MEMBERS'])) {
return false;
}
return ($member->getHighestRole()->comparePositionTo($this->getHighestRole()) > 0);
} | [
"function",
"isBannable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
"===",
"$",
"this",
"->",
"guild",
"->",
"ownerID",
"||",
"$",
"this",
"->",
"id",
"===",
"$",
"this",
"->",
"client",
"->",
"user",
"->",
"id",
")",
"{",
"return",
"fal... | Whether the member can be banned by the client user.
@return bool | [
"Whether",
"the",
"member",
"can",
"be",
"banned",
"by",
"the",
"client",
"user",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L349-L360 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.kick | function kick(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->guild->removeGuildMember($this->guild->id, $this->id, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | php | function kick(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->guild->removeGuildMember($this->guild->id, $this->id, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | [
"function",
"kick",
"(",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"use",
"(",
"$",
"rea... | Kicks the guild member.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Kicks",
"the",
"guild",
"member",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L384-L390 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.permissionsIn | function permissionsIn($channel) {
$channel = $this->guild->channels->resolve($channel);
if(!($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildChannelInterface)) {
throw new \InvalidArgumentException('Given channel is not a guild channel');
}
return $channel->permissionsFor($this);
} | php | function permissionsIn($channel) {
$channel = $this->guild->channels->resolve($channel);
if(!($channel instanceof \CharlotteDunois\Yasmin\Interfaces\GuildChannelInterface)) {
throw new \InvalidArgumentException('Given channel is not a guild channel');
}
return $channel->permissionsFor($this);
} | [
"function",
"permissionsIn",
"(",
"$",
"channel",
")",
"{",
"$",
"channel",
"=",
"$",
"this",
"->",
"guild",
"->",
"channels",
"->",
"resolve",
"(",
"$",
"channel",
")",
";",
"if",
"(",
"!",
"(",
"$",
"channel",
"instanceof",
"\\",
"CharlotteDunois",
"... | Returns permissions for a member in a guild channel, taking into account roles and permission overwrites.
@param \CharlotteDunois\Yasmin\Interfaces\GuildChannelInterface|string $channel
@return \CharlotteDunois\Yasmin\Models\Permissions
@throws \InvalidArgumentException | [
"Returns",
"permissions",
"for",
"a",
"member",
"in",
"a",
"guild",
"channel",
"taking",
"into",
"account",
"roles",
"and",
"permission",
"overwrites",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L398-L405 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.removeRole | function removeRole($role, string $reason = '') {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
$role = $role->id;
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($role, $reason) {
$this->client->apimanager()->endpoints->guild->removeGuildMemberRole($this->guild->id, $this->id, $role, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | php | function removeRole($role, string $reason = '') {
if($role instanceof \CharlotteDunois\Yasmin\Models\Role) {
$role = $role->id;
}
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($role, $reason) {
$this->client->apimanager()->endpoints->guild->removeGuildMemberRole($this->guild->id, $this->id, $role, $reason)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
} | [
"function",
"removeRole",
"(",
"$",
"role",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"role",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Models",
"\\",
"Role",
")",
"{",
"$",
"role",
"=",
"$",
"role",
"->",... | Removes a role from the guild member. Resolves with $this.
@param \CharlotteDunois\Yasmin\Models\Role|string $role A role instance or role ID.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Removes",
"a",
"role",
"from",
"the",
"guild",
"member",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L413-L423 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.removeRoles | function removeRoles($roles, string $reason = '') {
if($roles instanceof \CharlotteDunois\Collect\Collection) {
$roles = $roles->all();
}
$roles = \array_filter($this->roles->all(), function ($role) use ($roles) {
return (!\in_array($role, $roles, true) && !\in_array(((string) $role->id), $roles, true));
});
return $this->edit(array('roles' => $roles), $reason);
} | php | function removeRoles($roles, string $reason = '') {
if($roles instanceof \CharlotteDunois\Collect\Collection) {
$roles = $roles->all();
}
$roles = \array_filter($this->roles->all(), function ($role) use ($roles) {
return (!\in_array($role, $roles, true) && !\in_array(((string) $role->id), $roles, true));
});
return $this->edit(array('roles' => $roles), $reason);
} | [
"function",
"removeRoles",
"(",
"$",
"roles",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"roles",
"instanceof",
"\\",
"CharlotteDunois",
"\\",
"Collect",
"\\",
"Collection",
")",
"{",
"$",
"roles",
"=",
"$",
"roles",
"->",
"all"... | Removes roles from the guild member. Resolves with $this.
@param \CharlotteDunois\Collect\Collection|array $roles A collection or array of role instances (or role IDs).
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Removes",
"roles",
"from",
"the",
"guild",
"member",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L431-L441 |
CharlotteDunois/Yasmin | src/Models/GuildMember.php | GuildMember.setNickname | function setNickname(string $nickname, string $reason = '') {
if($this->id === $this->client->user->id) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($nickname) {
$this->client->apimanager()->endpoints->guild->modifyCurrentNick($this->guild->id, $this->id, $nickname)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
}
return $this->edit(array('nick' => $nickname), $reason);
} | php | function setNickname(string $nickname, string $reason = '') {
if($this->id === $this->client->user->id) {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($nickname) {
$this->client->apimanager()->endpoints->guild->modifyCurrentNick($this->guild->id, $this->id, $nickname)->done(function () use ($resolve) {
$resolve($this);
}, $reject);
}));
}
return $this->edit(array('nick' => $nickname), $reason);
} | [
"function",
"setNickname",
"(",
"string",
"$",
"nickname",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
"===",
"$",
"this",
"->",
"client",
"->",
"user",
"->",
"id",
")",
"{",
"return",
"(",
"new",
"\\",
... | Set the nickname of the guild member. Resolves with $this.
@param string $nickname
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Set",
"the",
"nickname",
"of",
"the",
"guild",
"member",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/GuildMember.php#L469-L479 |
CharlotteDunois/Yasmin | src/Models/PermissionOverwrite.php | PermissionOverwrite.edit | function edit($allow, $deny = null, string $reason = '') {
$options = array(
'type' => $this->type
);
$allow = ($allow !== null ? $allow : $this->allow);
$deny = ($deny !== null ? $deny : $this->deny);
if($allow instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$allow = $allow->bitfield;
}
if($deny instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$deny = $deny->bitfield;
}
if($allow === $this->allow->bitfield && $deny === $this->deny->bitfield) {
throw new \InvalidArgumentException('One of allow or deny has to be changed');
}
if(\json_encode($allow) === \json_encode($deny)) {
throw new \InvalidArgumentException('Allow and deny must have different permissions');
}
$options['allow'] = $allow;
$options['deny'] = $deny;
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($options, $reason) {
$this->client->apimanager()->endpoints->channel->editChannelPermissions($this->channel->getId(), $this->id, $options, $reason)->done(function () use ($options, $resolve) {
$this->allow = new \CharlotteDunois\Yasmin\Models\Permissions(($options['allow'] ?? 0));
$this->deny = new \CharlotteDunois\Yasmin\Models\Permissions(($options['deny'] ?? 0));
$resolve($this);
}, $reject);
}));
} | php | function edit($allow, $deny = null, string $reason = '') {
$options = array(
'type' => $this->type
);
$allow = ($allow !== null ? $allow : $this->allow);
$deny = ($deny !== null ? $deny : $this->deny);
if($allow instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$allow = $allow->bitfield;
}
if($deny instanceof \CharlotteDunois\Yasmin\Models\Permissions) {
$deny = $deny->bitfield;
}
if($allow === $this->allow->bitfield && $deny === $this->deny->bitfield) {
throw new \InvalidArgumentException('One of allow or deny has to be changed');
}
if(\json_encode($allow) === \json_encode($deny)) {
throw new \InvalidArgumentException('Allow and deny must have different permissions');
}
$options['allow'] = $allow;
$options['deny'] = $deny;
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($options, $reason) {
$this->client->apimanager()->endpoints->channel->editChannelPermissions($this->channel->getId(), $this->id, $options, $reason)->done(function () use ($options, $resolve) {
$this->allow = new \CharlotteDunois\Yasmin\Models\Permissions(($options['allow'] ?? 0));
$this->deny = new \CharlotteDunois\Yasmin\Models\Permissions(($options['deny'] ?? 0));
$resolve($this);
}, $reject);
}));
} | [
"function",
"edit",
"(",
"$",
"allow",
",",
"$",
"deny",
"=",
"null",
",",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"this",
"->",
"type",
")",
";",
"$",
"allow",
"=",
"(",
"$",
"allow... | Edits the permission overwrite. Resolves with $this.
@param \CharlotteDunois\Yasmin\Models\Permissions|int|null $allow Which permissions should be allowed?
@param \CharlotteDunois\Yasmin\Models\Permissions|int|null $deny Which permissions should be denied?
@param string $reason The reason for this.
@return \React\Promise\ExtendedPromiseInterface
@throws \InvalidArgumentException | [
"Edits",
"the",
"permission",
"overwrite",
".",
"Resolves",
"with",
"$this",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/PermissionOverwrite.php#L99-L133 |
CharlotteDunois/Yasmin | src/Models/PermissionOverwrite.php | PermissionOverwrite.delete | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->channel->deleteChannelPermission($this->channel->getId(), $this->id, $reason)->then(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | php | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->channel->deleteChannelPermission($this->channel->getId(), $this->id, $reason)->then(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | [
"function",
"delete",
"(",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"use",
"(",
"$",
"r... | Deletes the permission overwrite.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Deletes",
"the",
"permission",
"overwrite",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/PermissionOverwrite.php#L140-L146 |
CharlotteDunois/Yasmin | src/Models/Invite.php | Invite.delete | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->invite->deleteInvite($this->code, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | php | function delete(string $reason = '') {
return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
$this->client->apimanager()->endpoints->invite->deleteInvite($this->code, $reason)->done(function () use ($resolve) {
$resolve();
}, $reject);
}));
} | [
"function",
"delete",
"(",
"string",
"$",
"reason",
"=",
"''",
")",
"{",
"return",
"(",
"new",
"\\",
"React",
"\\",
"Promise",
"\\",
"Promise",
"(",
"function",
"(",
"callable",
"$",
"resolve",
",",
"callable",
"$",
"reject",
")",
"use",
"(",
"$",
"r... | Deletes the invite.
@param string $reason
@return \React\Promise\ExtendedPromiseInterface | [
"Deletes",
"the",
"invite",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/Invite.php#L158-L164 |
CharlotteDunois/Yasmin | src/Models/DMChannel.php | DMChannel.isRecipient | function isRecipient($user) {
$user = $this->client->users->resolve($user);
return $this->recipients->has($user->id);
} | php | function isRecipient($user) {
$user = $this->client->users->resolve($user);
return $this->recipients->has($user->id);
} | [
"function",
"isRecipient",
"(",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"client",
"->",
"users",
"->",
"resolve",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"recipients",
"->",
"has",
"(",
"$",
"user",
"->",
"id",
... | Determines whether a given user is a recipient of this channel.
@param \CharlotteDunois\Yasmin\Models\User|string $user The User instance or user ID.
@return bool
@throws \InvalidArgumentException | [
"Determines",
"whether",
"a",
"given",
"user",
"is",
"a",
"recipient",
"of",
"this",
"channel",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/Models/DMChannel.php#L115-L118 |
CharlotteDunois/Yasmin | src/HTTP/APIRequest.php | APIRequest.request | function request() {
$url = $this->url.$this->endpoint;
$options = array(
'http_errors' => false,
'headers' => array(
'User-Agent' => 'DiscordBot (https://github.com/CharlotteDunois/Yasmin, '.\CharlotteDunois\Yasmin\Client::VERSION.')'
)
);
if(!empty($this->options['auth'])) {
$options['headers']['Authorization'] = $this->options['auth'];
} elseif(empty($this->options['noAuth']) && !empty($this->api->client->token)) {
$options['headers']['Authorization'] = 'Bot '.$this->api->client->token;
}
if(!empty($this->options['files']) && \is_array($this->options['files'])) {
$options['multipart'] = array();
foreach($this->options['files'] as $file) {
if(!isset($file['data']) && !isset($file['path'])) {
continue;
}
$field = ($file['field'] ?? 'file-'.\bin2hex(\random_bytes(3)));
$options['multipart'][] = array(
'name' => $field,
'contents' => (isset($file['data']) ? $file['data'] : \fopen($file['path'], 'r')),
'filename' => (isset($file['name']) ? $file['name'] : (isset($file['path']) ? \basename($file['path']) : $field.'.jpg'))
);
}
if(!empty($this->options['data'])) {
$options['multipart'][] = array(
'name' => 'payload_json',
'contents' => \json_encode($this->options['data'], self::$jsonOptions)
);
}
} elseif(!empty($this->options['data'])) {
$options['json'] = $this->options['data'];
}
if(!empty($this->options['querystring'])) {
$options['query'] = \http_build_query($this->options['querystring'], '', '&', \PHP_QUERY_RFC3986);
}
if(!empty($this->options['auditLogReason'])) {
$options['headers']['X-Audit-Log-Reason'] = \rawurlencode(\trim($this->options['auditLogReason']));
}
$request = new \RingCentral\Psr7\Request($this->method, $url);
$request->requestOptions = $options;
return $request;
} | php | function request() {
$url = $this->url.$this->endpoint;
$options = array(
'http_errors' => false,
'headers' => array(
'User-Agent' => 'DiscordBot (https://github.com/CharlotteDunois/Yasmin, '.\CharlotteDunois\Yasmin\Client::VERSION.')'
)
);
if(!empty($this->options['auth'])) {
$options['headers']['Authorization'] = $this->options['auth'];
} elseif(empty($this->options['noAuth']) && !empty($this->api->client->token)) {
$options['headers']['Authorization'] = 'Bot '.$this->api->client->token;
}
if(!empty($this->options['files']) && \is_array($this->options['files'])) {
$options['multipart'] = array();
foreach($this->options['files'] as $file) {
if(!isset($file['data']) && !isset($file['path'])) {
continue;
}
$field = ($file['field'] ?? 'file-'.\bin2hex(\random_bytes(3)));
$options['multipart'][] = array(
'name' => $field,
'contents' => (isset($file['data']) ? $file['data'] : \fopen($file['path'], 'r')),
'filename' => (isset($file['name']) ? $file['name'] : (isset($file['path']) ? \basename($file['path']) : $field.'.jpg'))
);
}
if(!empty($this->options['data'])) {
$options['multipart'][] = array(
'name' => 'payload_json',
'contents' => \json_encode($this->options['data'], self::$jsonOptions)
);
}
} elseif(!empty($this->options['data'])) {
$options['json'] = $this->options['data'];
}
if(!empty($this->options['querystring'])) {
$options['query'] = \http_build_query($this->options['querystring'], '', '&', \PHP_QUERY_RFC3986);
}
if(!empty($this->options['auditLogReason'])) {
$options['headers']['X-Audit-Log-Reason'] = \rawurlencode(\trim($this->options['auditLogReason']));
}
$request = new \RingCentral\Psr7\Request($this->method, $url);
$request->requestOptions = $options;
return $request;
} | [
"function",
"request",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
".",
"$",
"this",
"->",
"endpoint",
";",
"$",
"options",
"=",
"array",
"(",
"'http_errors'",
"=>",
"false",
",",
"'headers'",
"=>",
"array",
"(",
"'User-Agent'",
"=>",
"... | Returns the Guzzle Request.
@return \Psr\Http\Message\RequestInterface | [
"Returns",
"the",
"Guzzle",
"Request",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/HTTP/APIRequest.php#L115-L169 |
CharlotteDunois/Yasmin | src/HTTP/APIRequest.php | APIRequest.execute | function execute(?\CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface $ratelimit = null) {
$request = $this->request();
return \CharlotteDunois\Yasmin\Utils\URLHelpers::makeRequest($request, $request->requestOptions)->then(function ($response) use ($ratelimit) {
if(!$response) {
return -1;
}
$status = $response->getStatusCode();
$this->api->client->emit('debug', 'Got response for item "'.$this->endpoint.'" with HTTP status code '.$status);
$this->api->handleRatelimit($response, $ratelimit, $this->isReactionEndpoint());
if($status === 204) {
return 0;
}
$body = self::decodeBody($response);
if($status >= 400) {
$error = $this->handleAPIError($response, $body, $ratelimit);
if($error === null) {
return -1;
}
throw $error;
}
return $body;
});
} | php | function execute(?\CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface $ratelimit = null) {
$request = $this->request();
return \CharlotteDunois\Yasmin\Utils\URLHelpers::makeRequest($request, $request->requestOptions)->then(function ($response) use ($ratelimit) {
if(!$response) {
return -1;
}
$status = $response->getStatusCode();
$this->api->client->emit('debug', 'Got response for item "'.$this->endpoint.'" with HTTP status code '.$status);
$this->api->handleRatelimit($response, $ratelimit, $this->isReactionEndpoint());
if($status === 204) {
return 0;
}
$body = self::decodeBody($response);
if($status >= 400) {
$error = $this->handleAPIError($response, $body, $ratelimit);
if($error === null) {
return -1;
}
throw $error;
}
return $body;
});
} | [
"function",
"execute",
"(",
"?",
"\\",
"CharlotteDunois",
"\\",
"Yasmin",
"\\",
"Interfaces",
"\\",
"RatelimitBucketInterface",
"$",
"ratelimit",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"request",
"(",
")",
";",
"return",
"\\",
"Char... | Executes the request.
@param \CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface|null $ratelimit
@return \React\Promise\ExtendedPromiseInterface | [
"Executes",
"the",
"request",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/HTTP/APIRequest.php#L176-L206 |
CharlotteDunois/Yasmin | src/HTTP/APIRequest.php | APIRequest.decodeBody | static function decodeBody(\Psr\Http\Message\ResponseInterface $response) {
$body = (string) $response->getBody();
$type = $response->getHeader('Content-Type')[0];
if(\stripos($type, 'text/html') !== false) {
throw new \RuntimeException('Invalid API response: HTML response body received');
}
$json = \json_decode($body, true, 512, self::$jsonOptions);
if($json === null && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \RuntimeException('Invalid API response: '.\json_last_error_msg());
}
return $json;
} | php | static function decodeBody(\Psr\Http\Message\ResponseInterface $response) {
$body = (string) $response->getBody();
$type = $response->getHeader('Content-Type')[0];
if(\stripos($type, 'text/html') !== false) {
throw new \RuntimeException('Invalid API response: HTML response body received');
}
$json = \json_decode($body, true, 512, self::$jsonOptions);
if($json === null && \json_last_error() !== \JSON_ERROR_NONE) {
throw new \RuntimeException('Invalid API response: '.\json_last_error_msg());
}
return $json;
} | [
"static",
"function",
"decodeBody",
"(",
"\\",
"Psr",
"\\",
"Http",
"\\",
"Message",
"\\",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"body",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"type",
"=",
"$",
"... | Gets the response body from the response.
@param \Psr\Http\Message\ResponseInterface $response
@return mixed
@throws \RuntimeException
@throws \JsonException | [
"Gets",
"the",
"response",
"body",
"from",
"the",
"response",
"."
] | train | https://github.com/CharlotteDunois/Yasmin/blob/7c38faf5784b4bffbe0560931ebf43cc6fa10044/src/HTTP/APIRequest.php#L215-L229 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.