ES Modulesに移行
This commit is contained in:
parent
0c3df4245d
commit
69212dd99a
105 changed files with 3154 additions and 3230 deletions
|
@ -1,10 +1,10 @@
|
|||
import { config } from '../../config';
|
||||
import { Score } from '../types/score';
|
||||
import { defaultTemplate } from '../../backend/const';
|
||||
import { IUser } from '../types/user';
|
||||
import { createGacha } from './create-gacha';
|
||||
import {Count} from '../../backend/models/count';
|
||||
import {getDelta} from '../../backend/functions/get-scores';
|
||||
import { config } from '../../config.js';
|
||||
import { Score } from '../types/score.js';
|
||||
import { defaultTemplate } from '../../backend/const.js';
|
||||
import { IUser } from '../types/user.js';
|
||||
import { createGacha } from './create-gacha.js';
|
||||
import {Count} from '../../backend/models/count.js';
|
||||
import {getDelta} from '../../backend/functions/get-scores.js';
|
||||
|
||||
/**
|
||||
* 埋め込み変数の型
|
||||
|
@ -15,20 +15,20 @@ export type Variable = string | ((score: Score, user: IUser) => string);
|
|||
* 埋め込み可能な変数のリスト
|
||||
*/
|
||||
export const variables: Record<string, Variable> = {
|
||||
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(),
|
||||
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;
|
||||
const variableRegex = /\{([a-zA-Z0-9_]+?)}/g;
|
||||
|
||||
/**
|
||||
* スコア情報とユーザー情報からテキストを生成する
|
||||
|
@ -37,13 +37,13 @@ const variableRegex = /\{([a-zA-Z0-9_]+?)\}/g;
|
|||
* @returns 生成したテキスト
|
||||
*/
|
||||
export const format = (user: IUser, count: Count): string => {
|
||||
const score: Score = {
|
||||
...count,
|
||||
...getDelta(user, count),
|
||||
};
|
||||
const template = user.template || defaultTemplate;
|
||||
return template.replace(variableRegex, (m, name) => {
|
||||
const v = variables[name];
|
||||
return !v ? m : typeof v === 'function' ? v(score, user) : v;
|
||||
}) + '\n\n#misshaialert';
|
||||
const score: Score = {
|
||||
...count,
|
||||
...getDelta(user, count),
|
||||
};
|
||||
const template = user.template || defaultTemplate;
|
||||
return template.replace(variableRegex, (m, name) => {
|
||||
const v = variables[name];
|
||||
return !v ? m : typeof v === 'function' ? v(score, user) : v;
|
||||
}) + '\n\n#misshaialert';
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue