Skip to content

Commit

Permalink
Merge pull request #953 from tsg-ut/dev/settyan117/city-symbol-add-co…
Browse files Browse the repository at this point in the history
…unters

city-symbol: 実績用カウンターの追加・解除条件の修正
  • Loading branch information
settyan117 authored Oct 22, 2024
2 parents c7884f6 + cbceb67 commit 6b2688d
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions city-symbol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ const getCityInformation = async (city: CitySymbol): Promise<CityInformation> =>
};
};

const getRandomCitySymbol = async (prefList: PrefectureKanji[] = Object.keys(prefectures) as PrefectureKanji[], allowEasterEgg: boolean = true): Promise<City> => {
const getRandomCitySymbol = async (prefList: PrefectureKanji[] = Object.keys(prefectures) as PrefectureKanji[], allowEasterEgg = true): Promise<City> => {
if (allowEasterEgg) {
if (Math.random() < 1 / 1719) {
return {
Expand Down Expand Up @@ -465,12 +465,11 @@ class CitySymbolAteQuiz extends AteQuiz {
}
return 10;
}
else {
if (hintIndex === 0) {
return 45;
}
return 10;

if (hintIndex === 0) {
return 45;
}
return 10;
}
}

Expand All @@ -484,25 +483,25 @@ export default (slackClients: SlackInterface) => {

mutex.runExclusive(async () => {
try {
let matches;
let matches: RegExpMatchArray = null;
if (
message.text &&
(matches = message.text.match(/^(?:市?区?町?村?)章当てクイズ\s?(?<pref>\p{sc=Han}+[都道府県])?$/u))
(matches = (message.text as string).match(/^(?:市?区?町?村?)章当てクイズ\s?(?<pref>\p{sc=Han}+[都道府県])?$/u))
) {
const prefecture = matches?.groups?.pref;
const prefectureSpecified = matches?.groups?.pref;

if (prefecture && !Object.hasOwn(prefectures, prefecture)) {
if (prefectureSpecified && !Object.hasOwn(prefectures, prefectureSpecified)) {
await slackClients.webClient.chat.postMessage({
channel: message.channel,
text: `${prefecture}という都道府県は存在しないよ:angry:`,
text: `${prefectureSpecified}という都道府県は存在しないよ:angry:`,
username: '市章当てクイズ',
icon_emoji: ':cityscape:',
});
return;
}

const needPrefHint = !prefecture;
const city = prefecture ? await getRandomCitySymbol([prefecture as PrefectureKanji], false) : await getRandomCitySymbol();
const needPrefHint = !prefectureSpecified;
const city = prefectureSpecified ? await getRandomCitySymbol([prefectureSpecified as PrefectureKanji], false) : await getRandomCitySymbol();
const quizText = 'この市区町村章ど~こだ?';
const imageUrl = getWikimediaImageUrl(sample(city.files));
const correctAnswers = getCorrectAnswers(city);
Expand Down Expand Up @@ -667,23 +666,33 @@ export default (slackClients: SlackInterface) => {
};

const quiz = new CitySymbolAteQuiz(slackClients, problem, {
username: '市章当てクイズ' + (prefecture ? ` (${prefecture})` : ''),
username: `市章当てクイズ${prefectureSpecified ? ` (${prefectureSpecified})` : ''}`,
icon_emoji: ':cityscape:',
});
quiz.hasPrefHint = needPrefHint;
const result = await quiz.start();

if (result.state === 'solved' && !prefecture) {
const hintCount = result.hintIndex + (prefectureSpecified ? 1 : 0);

if (result.state === 'solved') {
await increment(result.correctAnswerer, 'city-symbol-answer');
if (result.hintIndex === 0) {
if (hintCount === 0) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-hint');
}
if (result.hintIndex <= 1) {
if (hintCount <= 1) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-chatgpt-hint');
}
}
if (city.cityName === '博多市') {
await increment(result.correctAnswerer, 'city-symbol-answer-hakatashi');
if (city.cityName === '博多市') {
await increment(result.correctAnswerer, 'city-symbol-answer-hakatashi');
} else {
await increment(result.correctAnswerer, `city-symbol-answer-${city.prefectureName}`);
if (hintCount === 0) {
await increment(result.correctAnswerer, `city-symbol-answer-no-hint-${city.prefectureName}`);
}
if (hintCount <= 1) {
await increment(result.correctAnswerer, `city-symbol-answer-no-chatgpt-hint-${city.prefectureName}`);
}
}
}
}
} catch (error) {
Expand Down

0 comments on commit 6b2688d

Please sign in to comment.