Skip to content

Commit

Permalink
preparation for starboard system
Browse files Browse the repository at this point in the history
  • Loading branch information
shidoitsuka committed Nov 9, 2019
1 parent c7ba645 commit 3bb0fb1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
21 changes: 21 additions & 0 deletions events/messageReactionAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const Discord = require("discord.js");
const fs = require("fs");

module.exports = async (reaction, user) => {
// if (!reaction.message.guild.members.get(user.id).permissions.has("MANAGE_GUILD")) return;
if (user.id != '332424370272337923') return;
if (reaction.emoji.name != "⭐") return;
let star = JSON.parse(fs.readFileSync("./assets/g.json", "utf8"));
if (!reaction.message.guild.id in star) return reaction.message.channel.send("You haven\'t set starboard channel yet!");
let msg;

if (reaction.message.partial) {
try {
msg = await reaction.message.fetch();
} catch (e) {
console.log(e);
}
}
msg = reaction.message;
reaction.message.guild.channels.get(star[reaction.message.guild.id]).send(msg);
};
19 changes: 16 additions & 3 deletions modules/function.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chalk = require("chalk");
const walker = require("walker");
const { get } = require("snekfetch");
const fs = require("fs");

module.exports = (bot, message) => {
Expand All @@ -23,13 +24,17 @@ module.exports = (bot, message) => {
// LOAD COMMAND
bot.loadCommand = commandName => {
try {
/*
walker("./commands/").on("dir", dir => {
const category = dir.slice(dir.lastIndexOf("/") + 1);
bot.availableCommands.set(category, []);
});
*/
// walk through the sub folders using walker
const folder = walker(`./commands/`).on("file", file => {
if (!file.endsWith(".js")) return;
const props = require(`../${file}`);
if (props.init) {
props.init(bot);
}
if (props.init) props.init(bot);
// set command's config
bot.commandsConf.set(props.help.name, props.conf.guildOnly);
// set the command's name
Expand All @@ -40,6 +45,7 @@ module.exports = (bot, message) => {
props.conf.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
});
// bot.availableCommands.push(props.help.category, props.help.name);
});
console.log(chalk.bgWhite.black(`Loaded ${commandName}`));
return false;
Expand All @@ -60,4 +66,11 @@ module.exports = (bot, message) => {
if (err) console.log(err.stack);
});
};

fetchAvatar = (bot, userID, size) => {
if (typeof userID != "string")
throw new Error("Fetch Error: Type of UserID must be a string.");
const imageUrlRegex = /\?size=2048$/g;
return bot.users.get(userID).displayAvatarURL.replace(imageUrlRegex, size);
};
};
3 changes: 2 additions & 1 deletion util/eventLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const eventReq = (event) => require(`../events/${event}`);
module.exports = bot => {
bot.on('ready', () => eventReq('ready')(bot));
bot.on('guildMemberAdd', eventReq('guildMemberAdd'));
bot.on('messageReactionAdd', eventReq('messageReactionAdd'));
bot.on('message', eventReq('message'));
};
};

0 comments on commit 3bb0fb1

Please sign in to comment.