Skip to content

Commit

Permalink
Add support for custom status with variables
Browse files Browse the repository at this point in the history
  • Loading branch information
lavgup committed Mar 30, 2021
1 parent 416b549 commit 0ad93df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"token": "",
"prefixes": ["wu!"],
"lang": "en",
"status": {
"type": "watching",
"content": "$prefixhelp"
},
"owners": [""],
"guilds": {
"390342113042366465": {
Expand Down
20 changes: 18 additions & 2 deletions src/bot/listeners/client/ready.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { Listener } = require('discord-akairo');
const { version } = require('../../../../package.json');
const { prefixes, status } = require('../../../../config.json');

class ReadyListener extends Listener {
constructor() {
Expand All @@ -16,11 +18,25 @@ class ReadyListener extends Listener {
// noinspection JSUnresolvedVariable
this.client.user.setPresence({
activity: {
name: `${this.client.config.prefixes[0]}help`,
type: 'WATCHING'
name: this.replaceVars(status.content),
type: status.type.toUpperCase()
}
}).then(() => {});
}

replaceVars(content) {
const replacements = {
'$prefix': prefixes[0],
'$version': version,
'$guilds': this.client.guilds.cache.size
};

for (const [key, val] of Object.entries(replacements)) {
if (val) content = content.replace(key, val);
}

return content;
}
}

module.exports = ReadyListener;

0 comments on commit 0ad93df

Please sign in to comment.