Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
* test

* Bug Hunter Store v1.0.0
  • Loading branch information
KryptoCrash authored May 30, 2020
1 parent f8c8a4b commit 2d184d4
Show file tree
Hide file tree
Showing 30 changed files with 644 additions and 56 deletions.
Binary file added assets/launchFail.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/launchSuccess.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/takeOff.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bughuntertracker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
9 changes: 8 additions & 1 deletion colors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"standby": "#ded82a",
"valid": "#2ade2d",
"error": "#de2a2a",
"dev": "#ffffff"
"dev": "#ffffff",
"user": "#000000",
"tier0": "#c6c6c6",
"tier1": "#c8ae99",
"tier2": "#4ad46b",
"tier3": "#3dff66",
"tier4": "#6cff00",
"tier5": "#f7ff00"
}
55 changes: 55 additions & 0 deletions commands/addBugHunter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const Discord = require("discord.js");
const fs = require("fs");
const Perks = require("../utils/perks.js");
const devsio = require('../utils/devsio.js');
const colors = require("../colors.json");
const botsettings = require("../botsettings.json");
const prefix = botsettings.prefix;

module.exports.run = async (bot, message, args) => {
const member = message.guild.member(message.mentions.members.first() || args[0]);
const confirmationEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("SUCCESS")
.setDescription("This user is now a bug hunter! :tada:")
.setColor(colors.valid)

message.delete()

if(!member) return error(`ERROR: Incorrect usage. You must specify the member to add as a bug hunter. Correct Usage: \`${prefix}addbughunter bug_hunter\``);

devsio.readdevs(devs => {
if(!devs.includes(message.author.id)) return error("ERROR: Missing Permissions. You are not allowed to run this command.")
fs.readFile("./bughuntertracker.json", "utf8", async (err, data) => {
if(err) return console.error(err);
const bughunterArr = await JSON.parse(data);
const bughunter = bughunterArr.find(bughunter => bughunter.id === member.id);
if(!bughunter)
bughunterArr.push({id: member.id, tokens: 0, tier: 0, perks: new Perks()})
else return error("ERROR: This user is already a bug hunter");
const bughunterJSON = JSON.stringify(bughunterArr);
fs.writeFile("./bughuntertracker.json", bughunterJSON, "utf8", err => {
if(err) console.error(err);
});
message.channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
});
});

// Error Handler

function error(errorMessage) {
const errorEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("ERROR")
.setDescription(`${errorMessage}\nBug Hunter Addition process halted. Please run the command again to restart.`)
.setColor(colors.error);
message.channel.send(errorEmbed).then(msg => {
message.delete(0);
msg.delete(10000);
});
}
}
module.exports.help = {
name: "addbughunter",
description:"Adds a bug hunter."
};
101 changes: 101 additions & 0 deletions commands/buy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const Discord = require("discord.js");
const fs = require("fs");
const Perks = require("../utils/perks.js")
const colors = require("../colors.json");
const botsettings = require("../botsettings.json");
const storeJSON = require("../store.json");
const prefix = botsettings.prefix;
const bugHunterRoleID = botsettings.roleid_bughunter;

const perksPath = "../utils/Perks/";

/**
*
* @param {Discord.Client} bot
* @param {Discord.TextChannel} channel
*/
module.exports.run = async (bot, message, args) => {
let channel = message.channel;
let member = message.author;
let item = args.slice(0).join(" ");
let storeItems = {};
Object.entries(storeJSON).forEach(([key, val]) => storeItems[key.split("_").map(perk => perk.charAt(0).toUpperCase() + perk.slice(1)).join(" ")] = val);

if(!item) return error(`ERROR: Incorrect usage. Please specify an item to buy using: \`${prefix}buy Item_Name\`. If you are unsure of this item's name, you can use \`${prefix}store\` to check it.`)
item = item.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
if(!(storeItems.hasOwnProperty(item) || item.startsWith("Color Roles"))) return error(`ERROR: Incorrect usage. Could not find an item with the name of \`${item}\`. If you are unsure of this item's name, you can use \`${prefix}store\` to check it.`)

const tierColors = [colors.tier0, colors.tier1, colors.tier2, colors.tier3, colors.tier4, colors.tier5]
const tierRomanNumerals = ["I", "II", "III", "IV", "V"]
// Get user info
fs.readFile("./bughuntertracker.json", "utf8", async (err, data) => {
if(err) return console.error(err);
const bugHunterArr = JSON.parse(data);
const bugHunter = bugHunterArr.find(bughunter => bughunter.id === member.id);
if(bugHunter) {
const storeItem = storeItems[item] || storeItems["Color Roles"];
if(bugHunter.tokens < storeItem.tokens) return error(`ERROR: You do not have enough tokens to buy this item, you need \`${storeItem.tokens - bugHunter.tokens}\` more Bug Token.`);
try {
if(item.startsWith("Color Roles")) {
const perkUnlockResponse = await buyColorRole(args[2]);
if(perkUnlockResponse !== true) return error(perkUnlockResponse);
} else {
const perk = require(`${perksPath + item}.js`)
const perkUnlockResponse = perk.unlock(channel.guild, bugHunter);
if(perkUnlockResponse !== true) return error(perkUnlockResponse);
}
bugHunter.tokens -= storeItem.tokens;
} catch (err) {
return error(`ERROR: This item has not been implemented: \`(${err})\``)
}
} else return error("ERROR: Only Bug Hunters can use the store! If you would like to become a bug hunter, check out the <#711987145392390254> channel.");
const bugHunterJSON = JSON.stringify(bugHunterArr);
fs.writeFile("./bughuntertracker.json", bugHunterJSON, "utf8", err => {
if(err) {
console.error(err);
return error(`ERROR: Write to database failed. Please send the following message to Whimpers: (${err})`);
}
});
const confirmationEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("SUCCESS")
.setDescription("Your purchase was successfull! :tada:")
.setColor(colors.valid);
channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
});

message.delete(0);

async function buyColorRole(color) {
if(!color) return `ERROR: Incorrect Usage. Please specify a color. Correct usage: \`${prefix}buy Color Roles color\``;
if(!(/^#[0-9A-Fa-f]{6}$/).test(color)) return "ERROR: Color must be in a hex format. Example: #f00ba7";
const bugHunterRole = message.guild.roles.find(r => r.id === bugHunterRoleID);
const colorRole = await channel.guild.createRole({
name: color,
color: color,
position: bugHunterRole.position
})
message.guild.member(member).addRole(colorRole)
return true;
}

// Error Handler

function error(errorMessage) {
const errorEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("ERROR")
.setDescription(`${errorMessage}\nPurchase process halted. Please run the command again to restart.`)
.setColor(colors.error);
channel.send(errorEmbed).then(msg => {
message.delete(0);
msg.delete(10000);
});
}
};


module.exports.help = {
name: "buy",
description:"Purchases a perk from the store."
};
47 changes: 47 additions & 0 deletions commands/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Discord = require("discord.js");
const {isBugHunter} = require("../utils/isBugHunter.js")
const botSettings = require("../botsettings.json");
const colors = require("../colors.json");
const prefix = botSettings.prefix;

module.exports.run = async (bot, message, args) => {
message.delete();

if(!(isBugHunter(message.author.id) && isBugHunter(message.author.id).embederUnlocked)) return error(`ERROR: Missing permissions. You do not have the embeder perk unlocked.`)
if(args.length < 1) return error(`ERROR: Incorrect usage. You must specify a message to embed. Correct usage: \`${prefix}embed color message\``);

const colorTester = args[0];
let color;
let msg = args.slice(1).join(" ");

if((/[0-9A-Fa-f]{6}/g).test(colorTester)) {
color = colorTester;
} else {
msg = args.slice(0).join(" ");
}

let embed = new Discord.RichEmbed()
.setTitle(msg)
.setColor(color || colors.info)
.setFooter("- " + message.author.tag)
message.channel.send(embed);

// Error Handler

function error(errorMessage) {
const errorEmbed = new Discord.RichEmbed()
.setAuthor('Reviewer -', bot.avatarURL)
.setTitle("ERROR")
.setDescription(`${errorMessage}\nEmbeder process halted. Please run the command again to restart your report.`)
.setColor(colors.error)
message.channel.send(errorEmbed).then(msg => {
message.delete(0)
msg.delete(5000)
});
}
}

module.exports.help = {
name: "embed",
description: "Creates an embed with specified message"
}
2 changes: 2 additions & 0 deletions commands/forceAcceptReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Discord = require("discord.js");
const colors = require("../colors.json");
const BugReport = require("../utils/bugReport.js");
const devsio = require('../utils/devsio.js');
const {isBugHunter} = require("../utils/isBugHunter.js")
const fs = require("fs");
const botSettings = require("../botsettings.json")
const pending_channelid = botSettings.channelid_pendingbugs;
Expand Down Expand Up @@ -65,6 +66,7 @@ module.exports.run = async (bot, message, args) => {
})
message.delete(0);
})

// Error Handler

function error(errorMessage) {
Expand Down
1 change: 1 addition & 0 deletions commands/forceDenyReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Discord = require("discord.js");
const colors = require("../colors.json");
const BugReport = require("../utils/bugReport.js");
const devsio = require('../utils/devsio.js');
const {isBugHunter} = require("../utils/isBugHunter.js")
const fs = require("fs");
const botSettings = require("../botsettings.json");
const pending_channelid = botSettings.channelid_pendingbugs;
Expand Down
57 changes: 57 additions & 0 deletions commands/giveTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const Discord = require("discord.js");
const fs = require("fs");
const Perks = require("../utils/perks.js");
const devsio = require('../utils/devsio.js');
const colors = require("../colors.json");
const botsettings = require("../botsettings.json");
const prefix = botsettings.prefix;

module.exports.run = async (bot, message, args) => {
const member = message.guild.member(message.mentions.members.first() || args[0]);
const tokens = Number(args[1]);

const confirmationEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("SUCCESS")
.setDescription("Tokens given! :tada:")
.setColor(colors.valid)

message.delete()

if(!member || !tokens) return error(`ERROR: Incorrect usage. You must specify the bug hunter and the amount of tokens you want to give. Correct Usage: \`${prefix}givetokens bug_hunter token_count\``);

devsio.readdevs(devs => {
if(!devs.includes(message.author.id)) return error("ERROR: Missing Permissions. You are not allowed to run this command.")
fs.readFile("./bughuntertracker.json", "utf8", (err, data) => {
if(err) return console.error(err);
const bughunterArr = JSON.parse(data);
const bughunter = bughunterArr.find(bughunter => bughunter.id === member.id);
if(!bughunter)
bughunterArr.push({id: member.id, tokens: tokens, tier: 0, perks: new Perks()})
else bughunter.tokens += tokens;
const bughunterJSON = JSON.stringify(bughunterArr);
fs.writeFile("./bughuntertracker.json", bughunterJSON, "utf8", err => {
if(err) console.error(err);
});
message.channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
});
});

// Error Handler

function error(errorMessage) {
const errorEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("ERROR")
.setDescription(`${errorMessage}\nToken addition process halted. Please run the command again to restart.`)
.setColor(colors.error);
message.channel.send(errorEmbed).then(msg => {
message.delete(0);
msg.delete(10000);
});
}
}
module.exports.help = {
name: "givetokens",
description:"Gives tokens a bug hunter."
};
50 changes: 50 additions & 0 deletions commands/launch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const Discord = require('discord.js');
const {isBugHunter} = require("../utils/isBugHunter.js")
const colors = require("../colors.json");
const takeOff = new Discord.Attachment("./assets/takeOff.jpeg", "takeOff.jpeg");
const launchSuccess = new Discord.Attachment("./assets/launchSuccess.gif", "launchSuccess.gif");
const launchFail = new Discord.Attachment("./assets/launchFail.gif", "launchFail.gif");

module.exports.run = async (bot, message, args) => {
const user = message.mentions.users.first() || message.author;
const randomNumber = Math.round(Math.random());

message.delete()
if(!(isBugHunter(message.author.id) && isBugHunter(message.author.id).launcherUnlocked)) return error(`ERROR: Missing permissions. You do not have the launcher perk unlocked.`)

const launchEmbed = new Discord.RichEmbed()
.setAuthor('Reviewer -', bot.avatarURL)
.setTitle('LAUNCH')

if(randomNumber) {
launchEmbed.addField(`${user.username} was launched into space by ${message.author.username}!`, `${user.username}'s rocket flew to space!`);
launchEmbed.attachFile(launchSuccess)
launchEmbed.setImage("attachment://launchSuccess.gif");
launchEmbed.setColor(colors.valid)
} else {
launchEmbed.addField(`${user.username} was launched into space by ${message.author.username}!`, `${user.username}'s rocket blew up!`);
launchEmbed.attachFile(launchFail)
launchEmbed.setImage("attachment://launchFail.gif");
launchEmbed.setColor(colors.error)
}

message.channel.sendEmbed(launchEmbed)

// Error Handler

function error(errorMessage) {
const errorEmbed = new Discord.RichEmbed()
.setAuthor("Reviewer -", bot.avatarURL)
.setTitle("ERROR")
.setDescription(`${errorMessage}\nLauncher process halted. Please run the command again to restart.`)
.setColor(colors.error);
message.channel.send(errorEmbed).then(msg => {
msg.delete(10000);
});
}
}

module.exports.help = {
name: "launch",
description:"Launch someone into space!"
}
Loading

0 comments on commit 2d184d4

Please sign in to comment.