Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

city-symbol: 実績用カウンターの追加・解除条件の修正 #953

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions city-symbol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,20 @@ export default (slackClients: SlackInterface) => {
message.text &&
(matches = message.text.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,24 +667,38 @@ 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) {
await increment(result.correctAnswerer, 'city-symbol-answer');
if (result.hintIndex === 0) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-hint');
const hintCount = result.hintIndex + (prefectureSpecified ? 1 : 0);

if (result.state === 'solved') {
if (city.cityName === '博多市') {
await increment(result.correctAnswerer, 'city-symbol-answer');
await increment(result.correctAnswerer, 'city-symbol-answer-hakatashi');
if (hintCount === 0) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-hint');
}
if (hintCount <= 1) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-chatgpt-hint');
}
settyan117 marked this conversation as resolved.
Show resolved Hide resolved
}
if (result.hintIndex <= 1) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-chatgpt-hint');
else {
await increment(result.correctAnswerer, 'city-symbol-answer');
await increment(result.correctAnswerer, 'city-symbol-answer-' + city.prefectureName);
if (hintCount === 0) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-hint');
await increment(result.correctAnswerer, 'city-symbol-answer-no-hint-' + city.prefectureName);
settyan117 marked this conversation as resolved.
Show resolved Hide resolved
}
if (hintCount <= 1) {
await increment(result.correctAnswerer, 'city-symbol-answer-no-chatgpt-hint');
await increment(result.correctAnswerer, 'city-symbol-answer-no-chatgpt-hint-' + city.prefectureName);
}
}
}
if (city.cityName === '博多市') {
await increment(result.correctAnswerer, 'city-symbol-answer-hakatashi');
}
}
} catch (error) {
log.error(error.stack);
Expand Down
Loading