support guild-level enabling/disabling of some commands

This commit is contained in:
Chris Ham
2020-05-01 17:38:09 -07:00
parent 68d8d67fc5
commit f2bf3a7ad5
2 changed files with 56 additions and 23 deletions

View File

@@ -1,11 +1,36 @@
{
"botName": "greenhambot",
"d_token": "YOUR DISCORD APP TOKEN",
"adminID": "YOUR DISCORD USER ID",
"prefix": "!", // prefix that must precede all commands
"botChannel": "bot" // default channel where the bot will post things
"allowedSfxChannels": "bot", // channels where sfx can be used (separated by pipes)
"sfxVolume": 0.3,
"passes": 2, // can be increased to reduce packetloss at the expense of upload bandwidth, 4-5 should be lossless at the expense of 4-5x upload
"textCmdCooldown": 5 // default cooldown in seconds for all text commands
"debug": false,
"discord": {
"token": "YOUR DISCORD APP TOKEN",
"master": true,
"guilds": {
"GUILD ID": {
"internalName": "GUILD NAME",
"id": "GUILD ID",
"prefix": "!",
"enableSfx": true,
"allowedSfxChannels": "piped|list|of-valid-channels",
"sfxVolume": 0.5,
"passes": 2,
"enableFunFacts": true,
"enableHamFacts": true
},
"SECOND GUILD ID": {
"internalName": "SECOND GUILD NAME",
"id": "SECOND GUILD ID",
"prefix": "!",
"enableSfx": true,
"allowedSfxChannels": "piped|list|of-valid-channels",
"sfxVolume": 0.5,
"passes": 2,
"enableFunFacts": true,
"enableHamFacts": true
},
},
"activities": [
"that gum you like"
]
}
}

View File

@@ -108,7 +108,11 @@ function init(config) {
.on("start", () => {});
})(sfxPath.toString());
},
funfact: (msg) => {
funfact: (msg, guildConfig) => {
if (guildConfig.enableFunFacts === false) {
return;
}
if (funFacts.length > 0) {
// return random element from funFacts, unless one is specifically requested
let el;
@@ -134,7 +138,11 @@ function init(config) {
msg.channel.send("No fun facts found!");
}
},
hamfact: (msg) => {
hamfact: (msg, guildConfig) => {
if (guildConfig.enableHamFacts === false) {
return;
}
if (hamFacts.length > 0) {
// return random element from hamFacts, unless one is specifically requested
let el;
@@ -160,12 +168,12 @@ function init(config) {
msg.channel.send("No ham facts found!");
}
},
dance: (msg) => {
dance: (msg, guildConfig) => {
msg.channel.send(
"*┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛ ┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛ ┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛ ┏(-_-)┓┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┛*"
);
},
join: (msg) => {
join: (msg, guildConfig) => {
if (!msg.guild.voiceConnection) {
joinVoiceChannel(msg)
.then(() => {
@@ -176,7 +184,7 @@ function init(config) {
return msg.reply(`I'm already in a voice channel!`);
}
},
leave: (msg) => {
leave: (msg, guildConfig) => {
if (msg.guild.voiceConnection) {
msg.guild.voiceConnection.disconnect();
} else {
@@ -185,7 +193,7 @@ function init(config) {
);
}
},
listen: (msg) => {
listen: (msg, guildConfig) => {
// listen for a particular member to speak and respond appropriately
if (msg.guild.voiceConnection) {
// get the guild member
@@ -210,13 +218,13 @@ function init(config) {
// join the voice channel then call this command again
joinVoiceChannel(msg)
.then(() => {
commands.listen(msg);
commands.listen(msg, guildConfig);
})
.catch(console.error);
}
},
reboot: (msg) => {
if (msg.author.id == config.adminID) process.exit(); //Requires a node module like Forever to work.
reboot: (msg, guildConfig) => {
if (msg.author.id == config.discord.adminID) process.exit(); // Requires a node module like Forever to work.
}
};
@@ -233,6 +241,8 @@ function init(config) {
if (!config.discord.guilds[msg.guild.id]) {
return;
}
} else {
return;
}
// Find the guild config for this msg, use default if no guild (DM)
@@ -249,18 +259,16 @@ function init(config) {
.slice(guildConfig.prefix.length)
.split(" ")[0];
// check for native command first
if (commands.hasOwnProperty(commandNoPrefix)) {
console.log(
`'${commandNoPrefix}' received in ${guildConfig.internalName}#${msg.channel.name} from @${msg.author.username}`
);
// check for native command first
if (commands.hasOwnProperty(commandNoPrefix)) {
commands[commandNoPrefix](msg, guildConfig);
// then a static command we've manually added
} else if (staticCommands.exists(commandNoPrefix)) {
let result = staticCommands.get(commandNoPrefix);
console.log(
`'${commandNoPrefix}' received in ${guildConfig.internalName}#${msg.channel.name} from @${msg.author.username}`
);
msg.channel
.send({
embed: {
@@ -293,7 +301,7 @@ function init(config) {
if (!config.discord.guilds[member.guild.id]) {
return;
}
} else if (config.discord.handleDMs === false) {
} else {
return;
}