forked from MapComplete/MastodonBot
Add possibility to add config file, only send pietervdvn a message if the bot fails
This commit is contained in:
parent
5801c53038
commit
24b99f3e93
1 changed files with 12 additions and 13 deletions
21
src/index.ts
21
src/index.ts
|
@ -3,7 +3,6 @@ import * as fs from "fs"
|
||||||
import MastodonPoster from "./Mastodon";
|
import MastodonPoster from "./Mastodon";
|
||||||
import OsmCha, {ChangeSetData} from "./OsmCha";
|
import OsmCha, {ChangeSetData} from "./OsmCha";
|
||||||
import Config, {MapCompleteUsageOverview} from "./Config";
|
import Config, {MapCompleteUsageOverview} from "./Config";
|
||||||
import * as configF from "../config/config.json"
|
|
||||||
import {Postbuilder} from "./Postbuilder";
|
import {Postbuilder} from "./Postbuilder";
|
||||||
import Utils from "./Utils";
|
import Utils from "./Utils";
|
||||||
|
|
||||||
|
@ -11,8 +10,16 @@ export class Main {
|
||||||
|
|
||||||
private readonly _config: Config;
|
private readonly _config: Config;
|
||||||
|
|
||||||
constructor(config: Config) {
|
constructor(config: string | Config) {
|
||||||
|
if(config === undefined){
|
||||||
|
console.log("Needs an argument: path of config file")
|
||||||
|
throw "No path given"
|
||||||
|
}
|
||||||
|
if (typeof config === "string") {
|
||||||
|
this._config = JSON.parse(fs.readFileSync(config, {encoding: "utf-8"}))
|
||||||
|
} else {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
|
}
|
||||||
this._config.osmBackend ??= "https://www.openstreetmap.org"
|
this._config.osmBackend ??= "https://www.openstreetmap.org"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +36,6 @@ export class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const notice = await poster.writeMessage("@pietervdvn@en.osm.town Starting MapComplete bot...", {
|
|
||||||
visibility: "direct"
|
|
||||||
})
|
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -42,16 +46,11 @@ export class Main {
|
||||||
|
|
||||||
const end = Date.now()
|
const end = Date.now()
|
||||||
const timeNeeded = Math.floor((end - start) / 1000)
|
const timeNeeded = Math.floor((end - start) / 1000)
|
||||||
await poster.writeMessage("@pietervdvn@en.osm.town Finished running MapComplete bot, this took " + timeNeeded + "seconds", {
|
|
||||||
inReplyToId: notice.id,
|
|
||||||
visibility: "direct"
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const end = Date.now()
|
const end = Date.now()
|
||||||
const timeNeeded = Math.floor((end - start) / 1000)
|
const timeNeeded = Math.floor((end - start) / 1000)
|
||||||
await poster.writeMessage("@pietervdvn@en.osm.town Running MapComplete bot failed in " + timeNeeded + "seconds, the error is " + e, {
|
await poster.writeMessage("@pietervdvn@en.osm.town Running MapComplete bot failed in " + timeNeeded + "seconds, the error is " + e, {
|
||||||
inReplyToId: notice.id,
|
|
||||||
visibility: "direct"
|
visibility: "direct"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -101,4 +100,4 @@ export class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
new Main(configF).main().then(_ => console.log("All done"))
|
new Main(process.argv[2]).main().then(_ => console.log("All done"))
|
||||||
|
|
Loading…
Reference in a new issue