commit f1677a66de6ea21acf8df7c395f8bafeb16555e1
parent f23126f2ab03000d0010962ad3ff94b2f9d072ff
Author: Demonstrandum <moi@knutsen.co>
Date: Wed, 18 Mar 2020 16:13:37 +0000
Fix how timezones are handled.
Diffstat:
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts
@@ -5,10 +5,10 @@ const WEATHER_URL = 'http://api.openweathermap.org/data/2.5/weather';
export default home_scope => {
const { message, args, SECRETS, CONFIG } = home_scope;
- if (args[0] === 'set'){
+ if (args[0] === 'set' && args.length > 1){
CONFIG.weather_locations[message.author.id] = args.tail().join(' ');
message.answer(`Your weather location has \
- been set to ${args.slice(1).join(' ')}`.squeeze());
+ been set to ${args.tail().join(' ')}`.squeeze());
} else {
const location = args[0]
? args.join(' ')
@@ -21,7 +21,9 @@ export default home_scope => {
.then(res => res.json())
.then(d => {
const date = new Date();
- const hour = (24 + date.getUTCHours() + d.timezone) % 24;
+ const tz = d.timezone / 3600; // TODO: What if `tz` has a fractional part...
+ const hour = (24 + date.getUTCHours() + tz) % 24;
+ console.log('UTC:', date.getUTCHours(), 'tz:', d.timezone);
const country = !d.sys ? 'somewhere' : d.sys.country;
if (d.main) {
message.answer(`${hour}:${date.getMinutes()} ${d.name}, \
@@ -32,7 +34,7 @@ export default home_scope => {
${d.main.temp_min}°C min`.squeeze());
} else {
message.answer(`Cannot get weather information`
- + ` from ${location}`);
+ + ` from ${location}.`);
}
})
.catch(error);
diff --git a/lib/default.ts b/lib/default.ts
@@ -56,11 +56,11 @@ export default {
// Below are the different kinds of _rules_.
respond: [
{
- match: "/^\\s*thanks.*\\s*$/i",
+ match: "/^\\s*thanks\p{P}*\\s*$/i",
response: 'Obama.'
},
{
- match: "/[^\p{L}\p{N}]bot[^\p{L}\p{N}]/i",
+ match: "/(^|[^\\p{L}\\p{N}])+bot([^\\p{L}\\p{N}]|$)+/ui",
respond: "The hell you sayn' about bots?"
}
],