Fetch Kaomoji list through API instead of Futami.

This commit is contained in:
flash 2025-04-21 01:49:58 +00:00
parent a887e811c1
commit 176db54a72
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
3 changed files with 38 additions and 5 deletions

View file

@ -49,7 +49,7 @@ const Flashii = function(baseUrl) {
const url = createUrl(path, fields);
if(params)
for(const name in params) {
if(name === 'fields')
if(name === 'fields' || params[name] === null || params[name] === undefined)
continue;
url.searchParams.set(name, params[name]);
@ -146,5 +146,38 @@ const Flashii = function(baseUrl) {
return body;
};
const verifyKaomojiId = id => {
if(typeof id === 'number')
id = id.toString();
if(/^([^0-9]+)$/gu.test(id))
throw new Error('id argument is not an acceptable kaomoji id.');
return id;
};
fii.v1.kaomoji = async function({ as=null, fields=null, fresh=false }) {
const { status, body } = await send({ method: 'GET', path: '/v1/kaomoji', params: { as }, fields, fresh });
if(status === 400)
throw new Error('As or fields argument contains unsupported value.');
if(status > 299)
throw new Error(`Failed to fetch kaomoji with error code ${status}.`);
return body;
};
fii.v1.kaomoji.kaomoji = async function({ id, fields=null, fresh=false }) {
id = verifyKaomojiId(id);
const { status, body } = await send({ method: 'GET', path: `/v1/kaomoji/${id}`, fields, fresh });
if(status === 400)
throw new Error('Fields argument contains unsupported value.');
if(status === 404)
throw new Error('Requested kaomoji does not exist.');
if(status > 299)
throw new Error(`Failed to fetch kaomoji "${id}" with error code ${status}.`);
return body;
};
return fii;
};

View file

@ -378,7 +378,7 @@ const MamiInit = async args => {
});
settings.watch('weeaboo', ev => {
if(ev.detail.value) Weeaboo.init();
if(ev.detail.value) Weeaboo.init(ctx.flashii);
});
settings.watch('osuKeysV2', ev => {

View file

@ -11,12 +11,12 @@ const Weeaboo = (function() {
const userSfx = new Map;
const pub = {};
pub.init = function() {
pub.init = function(flashii) {
if(kaomoji.length > 0)
return;
$xhr.get(futami.get('kaomoji'))
.then(resp => kaomoji = resp.text.split("\n"));
flashii.v1.kaomoji({ as: 'array' })
.then(list => kaomoji = list);
};
pub.getRandomKaomoji = function(allowEmpty, message) {