Added RPC for emotes list.
This commit is contained in:
parent
8e006c7003
commit
058b409adf
2 changed files with 44 additions and 0 deletions
40
src/Emoticons/EmotesRpcHandler.php
Normal file
40
src/Emoticons/EmotesRpcHandler.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\Emoticons;
|
||||||
|
|
||||||
|
use Index\XArray;
|
||||||
|
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcQuery};
|
||||||
|
|
||||||
|
final class EmotesRpcHandler implements RpcHandler {
|
||||||
|
use RpcHandlerCommon;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private Emotes $emotes
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[RpcQuery('misuzu:emotes:all')]
|
||||||
|
public function queryAll(bool $includeId = false, bool $includeOrder = false): array {
|
||||||
|
return XArray::select(
|
||||||
|
$this->emotes->getEmotes(orderBy: 'order'),
|
||||||
|
function($emote) use ($includeId, $includeOrder) {
|
||||||
|
$info = [
|
||||||
|
'url' => $emote->getUrl(),
|
||||||
|
'strings' => XArray::select(
|
||||||
|
$this->emotes->getEmoteStrings($emote),
|
||||||
|
fn($string) => $string->getString()
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
if($includeId)
|
||||||
|
$info['id'] = $emote->getId();
|
||||||
|
if($includeOrder)
|
||||||
|
$info['order'] = $emote->getOrder();
|
||||||
|
|
||||||
|
$rank = $emote->getMinRank();
|
||||||
|
if($rank != 0)
|
||||||
|
$info['min_rank'] = $rank;
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -292,6 +292,10 @@ class MisuzuContext {
|
||||||
$this->authCtx
|
$this->authCtx
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$rpcServer->register(new Emoticons\EmotesRpcHandler(
|
||||||
|
$this->emotes
|
||||||
|
));
|
||||||
|
|
||||||
$rpcServer->register(new Users\UsersRpcHandler(
|
$rpcServer->register(new Users\UsersRpcHandler(
|
||||||
$this->siteInfo,
|
$this->siteInfo,
|
||||||
$this->urls,
|
$this->urls,
|
||||||
|
|
Loading…
Reference in a new issue