ガチャ機能実装など
This commit is contained in:
parent
e46bbd9fa5
commit
06a47b18e3
8 changed files with 133 additions and 141 deletions
|
@ -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';
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue