0
0
Fork 0

ガチャ機能実装など

This commit is contained in:
Ebise Lutica 2022-05-07 02:53:10 +09:00
parent e46bbd9fa5
commit 06a47b18e3
8 changed files with 133 additions and 141 deletions

View file

@ -2,48 +2,28 @@ import { config } from '../../config';
import { Score } from '../types/score';
import { defaultTemplate } from '../../backend/const';
import { IUser } from '../types/user';
import { createGacha } from './create-gacha';
/**
*
*/
export type Variable = {
replace?: string | ((score: Score, user: IUser) => string);
};
export type Variable = string | ((score: Score, user: IUser) => string);
/**
*
*/
export const variables: Record<string, Variable> = {
notesCount: {
replace: (score) => String(score.notesCount),
},
followingCount: {
replace: (score) => String(score.followingCount),
},
followersCount: {
replace: (score) => String(score.followersCount),
},
notesDelta: {
replace: (score) => String(score.notesDelta),
},
followingDelta: {
replace: (score) => String(score.followingDelta),
},
followersDelta: {
replace: (score) => String(score.followersDelta),
},
url: {
replace: config.url,
},
username: {
replace: (_, user) => String(user.username),
},
host: {
replace: (_, user) => String(user.host),
},
rating: {
replace: (_, user) => String(user.rating),
},
notesCount: score => String(score.notesCount),
followingCount: score => String(score.followingCount),
followersCount: score => String(score.followersCount),
notesDelta: score => String(score.notesDelta),
followingDelta: score => String(score.followingDelta),
followersDelta: score => String(score.followersDelta),
url: config.url,
username: (_, user) => String(user.username),
host: (_, user) => String(user.host),
rating: (_, user) => String(user.rating),
gacha: () => createGacha(),
};
const variableRegex = /\{([a-zA-Z0-9_]+?)\}/g;
@ -58,6 +38,6 @@ export const format = (score: Score, user: IUser): string => {
const template = user.template || defaultTemplate;
return template.replace(variableRegex, (m, name) => {
const v = variables[name];
return !v || !v.replace ? m : typeof v.replace === 'function' ? v.replace(score, user) : v.replace;
return !v ? m : typeof v === 'function' ? v(score, user) : v;
}) + '\n\n#misshaialert';
};