From ff1bdb2c1aba50994bad4065073cd74d5527f58e Mon Sep 17 00:00:00 2001 From: hibiya inemuri Date: Mon, 27 Nov 2023 19:44:53 +0900 Subject: [PATCH] Release 0.3.0: duplicants support --- package.json | 2 +- src/alias.js | 41 +++++++++++++++++++++++++++++++++++++---- src/index.js | 26 ++++++++++++++++++++++---- src/util.js | 11 +---------- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index db590d2..ca27e30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "djmax-topscore-worker", - "version": "0.2.4", + "version": "0.3.0", "devDependencies": { "wrangler": "2.12.1" }, diff --git a/src/alias.js b/src/alias.js index 42f03f6..d74f290 100644 --- a/src/alias.js +++ b/src/alias.js @@ -230,8 +230,8 @@ Sand Storm 샌드스톰 Secret Dejavu 시크릿데자뷰 Seeker 시커 Set Me Free 셋미프리 셋미 -Showdown 쇼다운 -Showdown (ez2on) 투온쇼다운 +Showdown (T3 쇼다운 +Showdown (EZ 투온쇼다운 SigNalize 시그널라이즈 Silent Clarity SIN 신 냐ㅜ @@ -300,11 +300,44 @@ ZET ZET ~Mr.Funky Remix~ ` -const ALIASES = Object.fromEntries(LINES.split('\n').flatMap(line => { +export const ALIASES = Object.fromEntries(LINES.split('\n').flatMap(line => { const [name, ...alias] = line.trim().split('\t') if(!name || !alias.length) return return alias.map(_ => [_, name]) }).filter(_ => _)) -export default ALIASES +export const PACKS = { + 'RESPECT': 'R', + 'V EXTENSION 4': 'VEX4', + 'V EXTENSION 3': 'VEX3', + 'V EXTENSION 2': 'VEX2', + 'TECHNIKA 1': 'T1', + 'TECHNIKA 2': 'T2', + 'TECHNIKA 3': 'T3', + 'EZ2ON REBOOT : R': 'EZ', + 'CYTUS': 'Cytus', + 'DEEMO': 'DeeMo', + 'MAPLESTORY': 'MS', + 'V EXTENSION': 'VEX1', + "GIRLS'FRONTLINE": 'GF', + 'BLACK SQUARE': 'BS', + 'PORTABLE 1': 'P1', + 'PORTABLE 2': 'P2', + 'PORTABLE 3': 'P3', + 'GROOVE COASTER': 'GC', + 'GUILTY GEAR': 'GG', + 'CLAZZIQUAI': 'CL', + 'MUSE DASH': 'MD', + 'CHUNITHM': 'CHU', + 'TECHNIKA TUNE & Q': 'TQ', + 'TRILOGY': 'TR', + 'CLEAR PASS+': 'CP+', + 'ESTIMATE': 'ESTi', + 'NEXON': 'NX', + 'Emotional Sense': 'ES' +} + +export const DUPLICATES = new Set([ + 'Showdown' +]) diff --git a/src/index.js b/src/index.js index 433d5d1..24143ca 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ */ import * as util from './util.js' +import { PACKS, DUPLICATES } from './alias.js' const API_BASE = `https://hard-archive.com/api` @@ -22,7 +23,11 @@ const fetchSonglist = async () => { return new Map( body.sort((a, b) => a.title.length - b.title.length) - .map(song => [ song.title.toLowerCase(), song ]) + .map(song => { + if(DUPLICATES.has(song.title)) + song.title += ` (${PACKS[song.pack]})` + return [ song.title.toLowerCase(), song ] + }) ) } @@ -99,12 +104,25 @@ export default { if(!songs) return _response(`곡 목록을 받아오지 못했습니다.`, { status: 500 }) - const foundTitle = util.findFirst(songs.keys(), title => title?.includes(parsed.title)) - const found = songs.get(foundTitle) + let title, foundTitle, found, foundKeys, foundPattern + const iter = songs.keys() + + while((title = iter.next()?.value) && title && !iter.done) { + if(!title.includes(parsed.title)) + continue + foundTitle = title + + if(!(found = songs.get(title))) + continue + + [ foundKeys, foundPattern ] = findPattern(found.pattern, parsed.button, parsed.pattern) + if(foundKeys && foundPattern) + break + } + if(!found) return _response(`검색어 '${parsed.title}'로 찾은 곡이 없습니다.`, { status: 404 }) - const [ foundKeys, foundPattern ] = findPattern(found.pattern, parsed.button, parsed.pattern) if(!foundPattern) return _response(`'${found.title}'에 ${parsed.button}버튼 ${parsed.pattern || '시험범위'} 패턴이 있나?`, { status: 404 }) diff --git a/src/util.js b/src/util.js index 65fa404..cc96554 100644 --- a/src/util.js +++ b/src/util.js @@ -1,4 +1,4 @@ -import ALIASES from './alias.js' +import { ALIASES } from './alias.js' export const parseCommand = message => { let match, title, button, pattern @@ -25,12 +25,3 @@ export const parseCommand = message => { return null } - -export const findFirst = (iterator, condition) => { - let item - while((item = iterator.next()) && !item.done) { - if(condition(item.value)) { - return item.value - } - } -}