Don't load commands if env variable doesn't exist, removed catfact/dogfact, many other changes

This commit is contained in:
TheEssem 2019-11-29 20:00:14 -06:00
parent 0920c459d5
commit 16927d8667
20 changed files with 116 additions and 83 deletions

View file

@ -2,4 +2,3 @@ const { Collection } = require("eris");
exports.commands = new Collection();
exports.aliases = new Collection();
exports.voiceConnections = new Collection();

View file

@ -1,39 +1,37 @@
// workaround for a gm bug where it doesn't output buffers properly
// https://github.com/aheckmann/gm/issues/572#issuecomment-293768810
module.exports = (data, format) => {
return new Promise((resolve, reject) => {
if (format) {
data.stream(format, (err, stdout, stderr) => {
if (err) return reject(err);
const chunks = [];
stdout.on("data", (chunk) => {
chunks.push(chunk);
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => {
resolve(Buffer.concat(chunks));
});
stderr.once("data", (data) => {
reject(String(data));
});
module.exports = async (data, format) => {
if (format) {
data.stream(format, (err, stdout, stderr) => {
if (err) throw err;
const chunks = [];
stdout.on("data", (chunk) => {
chunks.push(chunk);
});
} else {
data.stream((err, stdout, stderr) => {
if (err) return reject(err);
const chunks = [];
stdout.on("data", (chunk) => {
chunks.push(chunk);
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => {
resolve(Buffer.concat(chunks));
});
stderr.once("data", (data) => {
reject(String(data));
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => {
return Buffer.concat(chunks);
});
}
});
};
stderr.once("data", (data) => {
throw data;
});
});
} else {
data.stream((err, stdout, stderr) => {
if (err) throw err;
const chunks = [];
stdout.on("data", (chunk) => {
chunks.push(chunk);
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => {
return Buffer.concat(chunks);
});
stderr.once("data", (data) => {
throw data;
});
});
}
};

View file

@ -1,8 +1,15 @@
const collections = require("./collections.js");
const logger = require("./logger.js");
// load command into memory
exports.load = async (command) => {
const props = require(`../commands/${command}`);
if (props.requires === "google" && process.env.GOOGLE === "") return logger.log("info", `Google info not provided in config, skipped loading command ${command}...`);
if (props.requires === "cat" && process.env.CAT === "") return logger.log("info", `Cat API info not provided in config, skipped loading command ${command}...`);
if (props.requires === "mashape" && process.env.MASHAPE === "") return logger.log("info", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
if (props.requires === "twitter" && process.env.TWITTER === "false") return logger.log("info", `Twitter bot disabled, skipped loading command ${command}...`);
collections.commands.set(command.split(".")[0], props.run);
// add each alias to
if (props.aliases) {
props.aliases.forEach(alias => {
collections.aliases.set(alias, command.split(".")[0]);
@ -11,6 +18,7 @@ exports.load = async (command) => {
return false;
};
// unload command from memory
exports.unload = async (command) => {
let cmd;
if (collections.commands.has(command)) {

View file

@ -32,12 +32,21 @@ exports.clean = async (text) => {
exports.getTweet = async (tweets, reply = false, isDownload = false) => {
const randomTweet = this.random(reply ? (isDownload ? tweets.download : tweets.replies) : tweets.tweets);
if (randomTweet.match("{{message}}")) {
return randomTweet.replace(/{{message}}/g, await this.getRandomMessage());
return randomTweet.replace(/{{message}}/gm, await this.getRandomMessage());
} else {
return randomTweet.replace(/{{media}}/g, this.random(tweets.media))
.replace(/{{games}}/g, this.random(tweets.games))
.replace(/{{phrases}}/g, this.random(tweets.phrases))
.replace(/{{characters}}/g, this.random(tweets.characters));
return randomTweet
.replace(/{{media}}/gm, () => {
return this.random(tweets.media);
})
.replace(/{{games}}/gm, () => {
return this.random(tweets.games);
})
.replace(/{{phrases}}/gm, () => {
return this.random(tweets.phrases);
})
.replace(/{{characters}}/gm, () => {
return this.random(tweets.characters);
});
}
};

View file

@ -52,7 +52,13 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
}
}
});
reactionCollector.on("end", () => currentPage.removeReactions());
reactionCollector.on("end", () => {
try {
currentPage.removeReactions();
} catch (e) {
console.log("Reaction message was deleted");
}
});
return currentPage;
};
module.exports = paginationEmbed;

View file

@ -1,23 +1,19 @@
const client = require("./client.js");
const fs = require("fs");
const logger = require("./logger.js");
const connections = require("./collections.js").voiceConnections;
module.exports = async (sound, message) => {
if (message.member.voiceState.channelID) {
if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I can't join this voice channel!`);
const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID);
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return client.createMessage(message.channel.id, `${message.author.mention}, I don't have permission to join this voice channel!`);
const checkConnection = connections.get(message.channel.guild.id);
const connection = checkConnection ? checkConnection : await voiceChannel.join();
const connection = await voiceChannel.join();
const playingMessage = await client.createMessage(message.channel.id, "🔊 Playing sound...");
connections.set(message.channel.guild.id, connection);
if (connection.playing) {
connection.stopPlaying();
}
connection.play(fs.createReadStream(sound));
connection.on("error", (error) => {
connections.delete(message.channel.guild.id);
voiceChannel.leave();
playingMessage.delete();
logger.error(error);
@ -26,7 +22,6 @@ module.exports = async (sound, message) => {
logger.warn(warn);
});
connection.once("end", () => {
connections.delete(message.channel.guild.id);
voiceChannel.leave();
playingMessage.delete();
});