Command handler stuff, presences, other stuff

This commit is contained in:
Isaac
2021-02-18 18:41:35 +00:00
parent 7c0b1311dc
commit bdcff221db
15 changed files with 435 additions and 109 deletions

45
src/utils/discord.js Normal file
View File

@@ -0,0 +1,45 @@
// eslint-disable-next-line no-unused-vars
const { PresenceData } = require('discord.js');
const config = require('../../user/config');
let current_presence = -1;
module.exports = {
/**
* Select a presence from the config
* @returns {PresenceData}
*/
selectPresence() {
let length = config.presence.presences.length;
if (length === 0) return {};
let num;
if (length === 1)
num = 0;
else if (config.presence.randomise)
num = Math.floor(Math.random() * length);
else {
current_presence = current_presence + 1; // ++ doesn't work on negative numbers
if (current_presence === length)
current_presence = 0;
num = current_presence;
}
let {
activity: name,
status,
type,
url
} = config.presence.presences[num];
return {
activity: {
name,
type,
url
},
status
};
}
};

View File

@@ -1,5 +1,10 @@
const { join } = require('path');
module.exports = {
/**
* Make a relative path absolute
* @param {string} path - A path relative to the root of the project (like "./user/config.js")
* @returns {string} absolute path
*/
path: path => join(__dirname, '../../', path),
};