Skip to content

Commit

Permalink
randommeme use credentials if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Supinic committed Dec 5, 2024
1 parent 76e1761 commit 3e1b7a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# API_OCR_SPACE=
# API_OPEN_EXCHANGE_RATES=
# API_OPEN_WEATHER_MAP=
# API_REDDIT_USERNAME=
# API_REDDIT_SECRET=
# API_RIOT_GAMES_KEY=
# API_RUSTLOG_ADMIN_KEY=
# API_STEAM_KEY=
Expand Down
13 changes: 11 additions & 2 deletions commands/randommeme/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
let redditGotInstance;
const redditGot = (...args) => {
redditGotInstance ??= sb.Got.get("GenericAPI").extend({
const options = {
prefixUrl: "https://www.reddit.com/r/",
throwHttpErrors: false,
headers: {
Cookie: "_options={%22pref_quarantine_optin%22:true,%22pref_gated_sr_optin%22:true};"
}
});
};

if (process.env.API_REDDIT_USERNAME && process.env.API_REDDIT_SECRET) {
options.username = process.env.API_REDDIT_USERNAME;
options.password = process.env.API_REDDIT_SECRET;
}
else {
console.log("$rm command will not use authorized requests - no credentials found");
}

redditGotInstance ??= sb.Got.get("GenericAPI").extend(options);
return redditGotInstance(...args);
};

Expand Down

0 comments on commit 3e1b7a9

Please sign in to comment.