add and implement config file
This commit is contained in:
parent
ac689911ac
commit
29eb393717
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
./accessToken.json*
|
||||
node_app/media
|
||||
node_app/media
|
||||
node_app/config.json
|
7
node_app/example.config.json
Normal file
7
node_app/example.config.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"baseUrl": "https://social.cybre.town",
|
||||
"memeAPI": "http://redditapi.adb.sh/api/v1/",
|
||||
"subreddits": ["r/programmerhumor/random"],
|
||||
"allowedMedia": ["jpg", "jpeg", "gif", "png"],
|
||||
"interval": 60
|
||||
}
|
@ -1,16 +1,18 @@
|
||||
import {MastodonTokenHandler} from "./mastodonTokenHandler.js";
|
||||
import {mastodonMemeBot} from "./mastodonMemeBot.js";
|
||||
import {loadData} from "./JSONdataStore.js";
|
||||
|
||||
const config = {
|
||||
const config = loadData("./config.json")??{
|
||||
baseUrl: "https://social.cybre.town",
|
||||
memeAPI: "http://redditapi.adb.sh/api/v1/",
|
||||
subreddits: ["r/programmerhumor/random"],
|
||||
allowedMedia: ["jpg", "jpeg", "gif", "png"]
|
||||
allowedMedia: ["jpg", "jpeg", "gif", "png"],
|
||||
interval: 60
|
||||
};
|
||||
|
||||
let tokenHandler = new MastodonTokenHandler(config.baseUrl);
|
||||
let tokenHandler = new MastodonTokenHandler(config);
|
||||
tokenHandler.getAccessToken((accessToken) => {
|
||||
config.accessToken = accessToken;
|
||||
let bot = new mastodonMemeBot(config);
|
||||
bot.setFullInterval(60);
|
||||
bot.setFullInterval(config.interval);
|
||||
});
|
||||
|
@ -8,11 +8,12 @@ const rl = readline.createInterface({
|
||||
})
|
||||
|
||||
export class MastodonTokenHandler {
|
||||
constructor(baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
constructor(config) {
|
||||
this.config = config??loadData("./config.json");
|
||||
this.clientId;
|
||||
this.clientSecret;
|
||||
this.accessToken = loadData("./accessToken.json");
|
||||
this.accessToken = this.config.token;
|
||||
this.baseUrl = this.config.baseUrl;
|
||||
}
|
||||
getAccessToken(_callback){
|
||||
if (!this.accessToken) this.newAccessToken(_callback);
|
||||
@ -46,7 +47,8 @@ export class MastodonTokenHandler {
|
||||
.then((token) => {
|
||||
this.accessToken = token;
|
||||
console.log(`This is the access token. Save it!\n${this.accessToken}`)
|
||||
storeData(this.accessToken, "./accessToken.json");
|
||||
this.config.token = this.accessToken;
|
||||
storeData(this.config, "./config.json");
|
||||
_callback(this.accessToken);
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user