Fetch Kaomoji list through API instead of Futami.
This commit is contained in:
parent
a887e811c1
commit
176db54a72
3 changed files with 38 additions and 5 deletions
src/mami.js
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue