Skip to content

Commit

Permalink
Release 0.3.0: duplicants support
Browse files Browse the repository at this point in the history
  • Loading branch information
hibiyasleep committed Nov 27, 2023
1 parent 8b0d094 commit ff1bdb2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "djmax-topscore-worker",
"version": "0.2.4",
"version": "0.3.0",
"devDependencies": {
"wrangler": "2.12.1"
},
Expand Down
41 changes: 37 additions & 4 deletions src/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ Sand Storm 샌드스톰
Secret Dejavu 시크릿데자뷰
Seeker 시커
Set Me Free 셋미프리 셋미
Showdown 쇼다운
Showdown (ez2on) 투온쇼다운
Showdown (T3 쇼다운
Showdown (EZ 투온쇼다운
SigNalize 시그널라이즈
Silent Clarity
SIN 신 냐ㅜ
Expand Down Expand Up @@ -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'
])
26 changes: 22 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import * as util from './util.js'
import { PACKS, DUPLICATES } from './alias.js'

const API_BASE = `https://hard-archive.com/api`

Expand All @@ -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 ]
})
)
}

Expand Down Expand Up @@ -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 })

Expand Down
11 changes: 1 addition & 10 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ALIASES from './alias.js'
import { ALIASES } from './alias.js'

export const parseCommand = message => {
let match, title, button, pattern
Expand All @@ -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
}
}
}

0 comments on commit ff1bdb2

Please sign in to comment.