commit d8319fcce539e2c66e966f5608255107014c9e03
parent 718aa9872a208d531c9ef2e6f9a164bfb28390a7
Author: knutsen <samuel@knutsen.co>
Date: Thu, 29 Apr 2021 17:23:56 +0100
Round lat/lon down to 4 decimal places and provide unique User-Agent.
Weather API met.no has some strict requirements.
Diffstat:
5 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/Dockerfile b/Dockerfile
@@ -19,7 +19,7 @@ COPY heart.png generate_secrets.sh HELP.md lib \
COPY lib/drug-o-matic /app/lib/drug-o-matic
RUN yarn install
# Build
-RUN cp /app/bot.json /app/generate_secrets.sh /app/HELP.md /app/build/
+RUN cp /app/bot.json /app/generate_secrets.sh /app/HELP.md /app/package.json /app/build/
RUN /app/node_modules/.bin/tsc -b /app/tsconfig.json
# Run
diff --git a/build.sh b/build.sh
@@ -8,7 +8,7 @@ rm -rf ./build
mkdir -p ./build ./public
echo "${bold}Copying config files...${reset}"
-cp ./bot.json ./generate_secrets.sh ./HELP.md ./build
+cp ./bot.json ./generate_secrets.sh ./HELP.md ./package.json ./build
echo "${bold}Compiling TypeScript...${reset}"
./node_modules/.bin/tsc -b ./tsconfig.json
diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts
@@ -28,8 +28,8 @@ const WEATHER_URL = 'https://api.met.no/weatherapi/locationforecast/2.0/compact'
const OPENWEATHER_URL = 'https://api.openweathermap.org/data/2.5/weather';
const GEOCODE_URL = 'https://geocode-maps.yandex.ru/1.x/?format=json';
-export default async (home_scope: HomeScope) => {
- const { message, args, SECRETS, CONFIG } = home_scope;
+export default async (homescope: HomeScope) => {
+ const { message, args, SECRETS, CONFIG, VERSION } = homescope;
if (args[0] === 'set' && args.length > 1) {
CONFIG.weather_locations[message.author.id] = args.tail().join(' ');
@@ -66,10 +66,18 @@ export default async (home_scope: HomeScope) => {
.Address
.country_code;
- const [lon, lat] = geo_object.Point.pos.split(' ');
+ const [lon, lat] = geo_object.Point.pos
+ .split(' ')
+ .map(s => parseFloat(s).round_to(4));
tz = tzlookup(lat, lon)
weather_info = await fetch(
- `${WEATHER_URL}?lat=${lat}&lon=${lon}`);
+ `${WEATHER_URL}?lat=${lat}&lon=${lon}`,
+ {
+ method: 'get',
+ headers: {
+ 'User-Agent': `Simp-O-Matic/${VERSION} simp.knutsen.co`
+ }
+ });
openweather_info = await fetch(
`${OPENWEATHER_URL}?lat=${lat}&lon=${lon}`
+ `&units=metric&appid=${SECRETS.openweather.key}`);
diff --git a/lib/extensions.ts b/lib/extensions.ts
@@ -15,8 +15,8 @@ declare global {
(operator: string,
args: string[],
message: Message) => string,
- CLIENT: Client, main: SimpOMatic,
- INSTANCE_VARIABLES: Types.InstanceVariables,
+ CLIENT: Client, VERSION: string,
+ main: SimpOMatic, INSTANCE_VARIABLES: Types.InstanceVariables,
Drugs: any
};
@@ -103,6 +103,7 @@ declare global {
type GlobalConfig = {
name: string,
tag: string,
+ version: string,
permissions: number,
lang: 'en' | 'en-us' | 'en-gb',
guilds: { [key: string]: Config }
diff --git a/lib/main.ts b/lib/main.ts
@@ -38,11 +38,15 @@ const INSTANCE_VARIABLES = {
guilds: {}
}
+const PACKAGE = JSON.parse(read_file('./package.json').toString());
+export const VERSION = PACKAGE['version'] || "0.0.0";
+
// Anything that hasn't been defined in `bot.json`
// will be taken care of by the defaults.
let GLOBAL_CONFIG : Types.GlobalConfig = {
name: "Simp'O'Matic",
tag: "#1634",
+ version: VERSION,
permissions: 8,
lang: 'en',
@@ -367,8 +371,8 @@ Would you like to slow down a little?`.squeeze());
HELP_MESSAGES, HELP_SECTIONS, ALL_HELP,
CONFIG, SECRETS, KNOWN_COMMANDS,
expand_alias: this.expand_alias,
- CLIENT: SimpOMatic._CLIENT, main: this,
- INSTANCE_VARIABLES, Drugs
+ CLIENT: SimpOMatic._CLIENT, VERSION,
+ main: this, INSTANCE_VARIABLES, Drugs
};
const commands = read_dir(`${__dirname}/commands`)