Skip to content

Commit

Permalink
Merge pull request #935 from tsg-ut/city-symbol-fix
Browse files Browse the repository at this point in the history
city-symbol: 基礎自治体位置図テンプレートの省略記法に対応
  • Loading branch information
hakatashi authored Sep 29, 2024
2 parents c571c1a + 30ba316 commit d7a5db9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions city-symbol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ const getWikipediaSource = async (prefName: string) => {
return citySymbols;
};

const extractPlaceImage = (content: string) => {
{
const placeImageMatches = content.match(/.+\|image\s*=\s*(.+?)[|}]/);
if (placeImageMatches?.[1]) {
return placeImageMatches[1];
}
}

{
const placeImageMatches = content.match(/\{\{\|(\d+)\|(\d+)\}\}/);
if (placeImageMatches?.[1] && placeImageMatches?.[2]) {
const prefCode = placeImageMatches[1].padStart(2, '0');
const cityCode = placeImageMatches[2].padStart(3, '0');
return `基礎自治体位置図_${prefCode}${cityCode}.svg`;
}
}

throw new Error('Failed to extract place image');
};

const getCityInformation = async (title: string): Promise<CityInformation> => {
log.info(`Getting wikipedia ${title}...`);

Expand All @@ -113,8 +133,7 @@ const getCityInformation = async (title: string): Promise<CityInformation> => {
throw new Error('Failed to get wikipedia source');
}

const placeImageMatches = content.match(/.+\|image\s*=\s*(.+?)\|/);
const placeImage = placeImageMatches?.[1] ?? '';
const placeImage = extractPlaceImage(content);

const rubyMatches = content.match(/(.+?)/);
const ruby = rubyMatches?.[1] ?? '';
Expand All @@ -139,7 +158,7 @@ class CitySymbolAteQuiz extends AteQuiz {
}
}

export default async (slackClients: SlackInterface) => {
export default (slackClients: SlackInterface) => {
const {eventClient} = slackClients;

eventClient.on('message', (message) => {
Expand Down

0 comments on commit d7a5db9

Please sign in to comment.