Skip to content

Commit fe5fd1f

Browse files
committed
fix: cwa
1 parent 61663ab commit fe5fd1f

File tree

8 files changed

+292
-461
lines changed

8 files changed

+292
-461
lines changed

Commands/Weather/forecast.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports = {
180180
break;
181181
}
182182

183-
case "W37":{
183+
case "W37": {
184184
warn.setThumbnail("https://www.cwa.gov.tw/Data/warning/Surge_Swell/Swell_MapTaiwan02.png");
185185
break;
186186
}
@@ -222,7 +222,7 @@ module.exports = {
222222

223223
const forecast_embed = new EmbedBuilder()
224224
.setAuthor({
225-
name : "中央氣象局",
225+
name : "中央氣象署",
226226
iconURL : "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png",
227227
url : "https://www.cwa.gov.tw/",
228228
})
@@ -249,7 +249,8 @@ module.exports = {
249249
// ${+time[ti].elementValue[0].value < 16 ? "🥶" : time[ti].elementValue[0].value > 26 ? "🥵" : "😀"}
250250
forecast_embed.addFields({
251251
name : `${timestamp(new Date(time.startTime), TimestampStyles.ShortDateTime)} __${timeperiod(new Date(time.startTime))}__ ${emoji(values.Wx, timeperiod(new Date(time.startTime)))} ${values.Wx}`,
252-
value : lines.join("\n") });
252+
value : lines.join("\n"),
253+
});
253254
});
254255
embeds.push(forecast_embed);
255256

@@ -340,7 +341,7 @@ module.exports = {
340341
break;
341342
}
342343

343-
case "W37":{
344+
case "W37": {
344345
warn.setThumbnail("https://www.cwa.gov.tw/Data/warning/Surge_Swell/Swell_MapTaiwan02.png");
345346
break;
346347
}
@@ -384,7 +385,7 @@ module.exports = {
384385

385386
const forecast_embed = new EmbedBuilder()
386387
.setAuthor({
387-
name : "中央氣象局",
388+
name : "中央氣象署",
388389
iconURL : "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png",
389390
url : "https://www.cwa.gov.tw/",
390391
})
@@ -470,7 +471,7 @@ module.exports = {
470471
const time = new Date(fields.find(v => new Date(v.page).getDate() == date).page);
471472
buttons.push(new ButtonBuilder()
472473
.setStyle(buttons.length ? ButtonStyle.Secondary : ButtonStyle.Primary)
473-
.setLabel(`${time.getMonth() + 1}/${time.getDate()} (${[ "日", "一", "二", "三", "四", "五", "六" ][time.getDay()]})`)
474+
.setLabel(`${time.getMonth() + 1}/${time.getDate()} (${["日", "一", "二", "三", "四", "五", "六"][time.getDay()]})`)
474475
.setCustomId(`forecast-${paging.indexOf(date)}`));
475476
}
476477

Commands/Weather/typhoon.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = {
6464
const mainEmbed = new EmbedBuilder()
6565
.setColor(CycloneLevelColors[getCycloneLevel(current.maxWindSpeed)])
6666
.setAuthor({
67-
name : "中央氣象局",
67+
name : "中央氣象署",
6868
iconURL : "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png",
6969
url : "https://www.cwa.gov.tw/",
7070
})
@@ -80,7 +80,7 @@ module.exports = {
8080
const historyEmbed = new EmbedBuilder()
8181
.setColor(CycloneLevelColors[getCycloneLevel(current.maxWindSpeed)])
8282
.setAuthor({
83-
name : "中央氣象局",
83+
name : "中央氣象署",
8484
iconURL : "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png",
8585
url : "https://www.cwa.gov.tw/",
8686
})
@@ -227,17 +227,17 @@ module.exports = {
227227

228228
const cycloneIndex = 0;
229229

230-
const sent = await interaction.editReply({ embeds: cyclones[0].main, components: [ pages ] });
230+
const sent = await interaction.editReply({ embeds: cyclones[0].main, components: [pages] });
231231
const collector = sent.createMessageComponentCollector({ componentType: ComponentType.Button });
232232
collector.on("collect", async inter => {
233233
if (inter.customId == "typhoon-main")
234-
await inter.update({ embeds: cyclones[cycloneIndex].main, components: [ pages ] });
234+
await inter.update({ embeds: cyclones[cycloneIndex].main, components: [pages] });
235235

236236
if (inter.customId == "typhoon-history")
237-
await inter.update({ embeds: cyclones[cycloneIndex].history, components: [ pages ] });
237+
await inter.update({ embeds: cyclones[cycloneIndex].history, components: [pages] });
238238

239239
if (inter.customId == "typhoon-forecast")
240-
await inter.update({ embeds: cyclones[cycloneIndex].forecast, components: [ pages ] });
240+
await inter.update({ embeds: cyclones[cycloneIndex].forecast, components: [pages] });
241241
});
242242
}
243243
else
@@ -261,7 +261,7 @@ function getCycloneLevel(wind = 0, coord) {
261261
if (index == 0 && (coords?.latitude ?? 0) > 23.5)
262262
return "溫帶氣旋";
263263
else
264-
return [ "熱帶性低氣壓", "輕度颱風", "中度颱風", "強烈颱風" ][index];
264+
return ["熱帶性低氣壓", "輕度颱風", "中度颱風", "強烈颱風"][index];
265265
}
266266

267267
function parseCoordinate(coord) {

EventHandler/eew.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
once : false,
4545

4646
/**
47-
* @param {import("discord.js").Client} client
47+
* @param {import("discord.js").Client} client
4848
* @param {import("discord.js").Message} message The created message
4949
*/
5050
execute(client, message) {
@@ -55,8 +55,8 @@ module.exports = {
5555
try {
5656

5757
/**
58-
* @type {event}
59-
*/
58+
* @type {event}
59+
*/
6060
const event = JSON.parse(message.content);
6161

6262
if (event.topic != "CWA_EEW") return;
@@ -130,7 +130,7 @@ module.exports = {
130130
],
131131
)
132132
.setImage("https://upload.cc/i1/2022/11/30/6DOluI.png")
133-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" }).setFooter({ text: `發布於 ${pt.getHours() < 10 ? "0" : ""}${pt.getHours()}:${pt.getMinutes() < 10 ? "0" : ""}${pt.getMinutes()}:${pt.getSeconds() < 10 ? "0" : ""}${pt.getSeconds()}` })
133+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" }).setFooter({ text: `發布於 ${pt.getHours() < 10 ? "0" : ""}${pt.getHours()}:${pt.getMinutes() < 10 ? "0" : ""}${pt.getMinutes()}:${pt.getSeconds() < 10 ? "0" : ""}${pt.getSeconds()}` })
134134
.setTimestamp();
135135

136136
if (data.type == "Alert") {
@@ -212,8 +212,8 @@ function caldistance({ lat: lat1, lon: lon1 }, { lat: lat2, lon: lon2 }) {
212212
const p = 0.017453292519943295;
213213
const c = Math.cos;
214214
const a = 0.5 - c((lat2 - lat1) * p) / 2
215-
+ c(lat1 * p) * c(lat2 * p)
216-
* (1 - c((lon2 - lon1) * p)) / 2;
215+
+ c(lat1 * p) * c(lat2 * p)
216+
* (1 - c((lon2 - lon1) * p)) / 2;
217217

218218
return 12742 * Math.asin(Math.sqrt(a));
219219
}
@@ -238,11 +238,11 @@ const intensesTW = [
238238
*/
239239
/*
240240
function calIntensity(distance, magnitude, depth) {
241-
const PGAs = distance.map(v => PGA(magnitude, v, depth));
242-
return PGAs.map((v, index) => {
243-
const value = intenses[0.8, 2.5, 8.0, 25, 80, 140, 250, 440, 800, v].sort((a, b) => a - b).indexOf(v);
244-
return { pos: Object.keys(gov)[index], value, pga: v, label: intensesTW[value] };
245-
});
241+
const PGAs = distance.map(v => PGA(magnitude, v, depth));
242+
return PGAs.map((v, index) => {
243+
const value = intenses[0.8, 2.5, 8.0, 25, 80, 140, 250, 440, 800, v].sort((a, b) => a - b).indexOf(v);
244+
return { pos: Object.keys(gov)[index], value, pga: v, label: intensesTW[value] };
245+
});
246246
}
247247
*/
248248
function pgaToIntensity(pga) {
@@ -272,7 +272,7 @@ function calBearing(startLat, startLng, destLat, destLng) {
272272

273273
const y = Math.sin(destLng - startLng) * Math.cos(destLat);
274274
const x = Math.cos(startLat) * Math.sin(destLat)
275-
- Math.sin(startLat) * Math.cos(destLat) * Math.cos(destLng - startLng);
275+
- Math.sin(startLat) * Math.cos(destLat) * Math.cos(destLng - startLng);
276276
let brng = Math.atan2(y, x);
277277
brng = toDegrees(brng);
278278
return (brng + 360) % 360;

Functions/formatEarthquake.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ function formatEarthquake(Earthquake, style = 0) {
9292
+ ".html";
9393
const cwa_image
9494
= Earthquake.cwa_image ? Earthquake.cwa_image : "https://www.cwa.gov.tw/Data/earthquake/img/EC"
95-
+ (Earthquake.EarthquakeNo % 1000 == 0 ? "L" : "")
96-
+ (Earthquake.EarthquakeNo % 1000 == 0 ? timecode : timecode.slice(4, timecode.length - 2))
97-
+ (Earthquake.EarthquakeInfo.EarthquakeMagnitude.MagnitudeValue * 10)
98-
+ (Earthquake.EarthquakeNo % 1000 == 0 ? "" : Earthquake.EarthquakeNo.toString().substring(3))
99-
+ "_H.png";
95+
+ (Earthquake.EarthquakeNo % 1000 == 0 ? "L" : "")
96+
+ (Earthquake.EarthquakeNo % 1000 == 0 ? timecode : timecode.slice(4, timecode.length - 2))
97+
+ (Earthquake.EarthquakeInfo.EarthquakeMagnitude.MagnitudeValue * 10)
98+
+ (Earthquake.EarthquakeNo % 1000 == 0 ? "" : Earthquake.EarthquakeNo.toString().substring(3))
99+
+ "_H.png";
100100

101101
const url = new ActionRowBuilder()
102102
.addComponents([
@@ -123,7 +123,7 @@ function formatEarthquake(Earthquake, style = 0) {
123123
.setAuthor({ name: "地震報告", iconURL: "https://i.imgur.com/qIxk1H1.png" })
124124
.setThumbnail(cwa_image)
125125
.setDescription(desc)
126-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
126+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
127127
.setTimestamp(time);
128128

129129
return { embeds: [embed], components: [url] };
@@ -136,7 +136,7 @@ function formatEarthquake(Earthquake, style = 0) {
136136
.setAuthor({ name: "地震報告", iconURL: "https://i.imgur.com/qIxk1H1.png" })
137137
.setImage(cwa_image)
138138
.setDescription(desc)
139-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
139+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
140140
.setTimestamp(time);
141141

142142
return { embeds: [embed], components: [url] };
@@ -156,7 +156,7 @@ function formatEarthquake(Earthquake, style = 0) {
156156
.setAuthor({ name: "地震報告", iconURL: "https://i.imgur.com/qIxk1H1.png" })
157157
.setImage(cwa_image)
158158
.setDescription(desc)
159-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
159+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
160160
.setTimestamp(time);
161161

162162
Earthquake.Intensity.ShakingArea
@@ -186,7 +186,7 @@ function formatEarthquake(Earthquake, style = 0) {
186186
{ name: "震央", value: `${Earthquake.EarthquakeInfo.Epicenter.Location.replace("(", "(").replace(")", ")").split("(").join("\n(")}` },
187187
],
188188
)
189-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
189+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
190190
.setTimestamp(time);
191191

192192
Earthquake.Intensity.ShakingArea
@@ -217,7 +217,7 @@ function formatEarthquake(Earthquake, style = 0) {
217217
{ name: "規模", value: `${magnitudeE[magnitudeI]} 芮氏 **${Earthquake.EarthquakeInfo.EarthquakeMagnitude.MagnitudeValue}**\n  ${magnitudeTW[magnitudeI]}`, inline: true },
218218
],
219219
)
220-
.setFooter({ text: "交通部中央氣象局", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
220+
.setFooter({ text: "交通部中央氣象署", iconURL: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/ROC_Central_Weather_Bureau.svg/1200px-ROC_Central_Weather_Bureau.svg.png" })
221221
.setTimestamp(time);
222222

223223
Earthquake.Intensity.ShakingArea

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = require("./config");
66
const fetch = require("node-fetch").default;
77
const readline = require("node:readline");
88
const { stripIndent } = require("common-tags");
9-
const cwb = new (require("./API/cwb_forecast"))(process.env.CWB_TOKEN);
9+
const cwa = new (require("./API/cwa_forecast"))(process.env.CWA_TOKEN);
1010
process.env.DEBUG_MODE = config.debug;
1111

1212
Kami.version = process.env.BOT_VERSION;
@@ -194,8 +194,8 @@ setInterval(() => {
194194

195195
async function updateData() {
196196
try {
197-
const fetched_data = (await cwb.earthquake_report({ format: "json" }).catch(() => void 0))?.records?.Earthquake;
198-
const fetched_data_s = (await cwb.earthquake_report_s({ format: "json" }).catch(() => void 0))?.records?.Earthquake;
197+
const fetched_data = (await cwa.earthquake_report({ format: "json" }).catch(() => void 0))?.records?.Earthquake;
198+
const fetched_data_s = (await cwa.earthquake_report_s({ format: "json" }).catch(() => void 0))?.records?.Earthquake;
199199

200200
if (fetched_data != undefined) {
201201
Kami.data.quake_last = Kami.data.quake_data;

0 commit comments

Comments
 (0)