diff --git a/src/common/functions/create-gacha.ts b/src/common/functions/create-gacha.ts new file mode 100644 index 0000000..15c5973 --- /dev/null +++ b/src/common/functions/create-gacha.ts @@ -0,0 +1,25 @@ +const allKatakana = [ + ...('アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨ'.split('')), + 'ウィ', 'ウェ', + 'キャ', 'キュ', 'キョ', + 'クァ', 'クォ', + 'シャ', 'シュ', 'ショ', + 'チャ', 'チュ', 'チョ', + 'ヒャ', 'ヒュ', 'ヒョ', + 'ミャ', 'ミュ', 'ミョ' +]; + +const allInfix = [ '', 'ー', 'ッ' ]; + +const getRandomKatakana = () => allKatakana[Math.floor(Math.random() * allKatakana.length)]; +const getRandomInfix = () => allInfix[Math.floor(Math.random() * allInfix.length)]; + +export const createGacha = () => { + return [ + getRandomKatakana(), + getRandomInfix(), + getRandomKatakana(), + getRandomInfix(), + ...(new Array(Math.floor(Math.random() * 2 + 1)).fill('').map(() => getRandomKatakana())) + ].join(''); +}; diff --git a/src/common/functions/format.ts b/src/common/functions/format.ts index 5ff2ff9..d1c9c35 100644 --- a/src/common/functions/format.ts +++ b/src/common/functions/format.ts @@ -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 = { - 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'; }; diff --git a/src/frontend/components/AdminPage.tsx b/src/frontend/components/AdminPage.tsx index 362dec3..a2cd132 100644 --- a/src/frontend/components/AdminPage.tsx +++ b/src/frontend/components/AdminPage.tsx @@ -132,76 +132,72 @@ export const AdminPage: React.VFC = () => {

You are not an administrator and cannot open this page.

) : ( <> -
-

Announcements

- {!isEditMode && ( - - )} - - { !isEditMode ? ( - <> - {isDeleteMode &&
Click the item to delete.
} -
- {announcements.map(a => ( - - ))} - {!isDeleteMode && ( - - )} -
- - ) : ( -
- -