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

Commit 2d184d4

Browse files
authored
* test * Bug Hunter Store v1.0.0
1 parent f8c8a4b commit 2d184d4

30 files changed

+644
-56
lines changed

assets/launchFail.gif

1.46 MB
Loading

assets/launchSuccess.gif

1.29 MB
Loading

assets/takeOff.jpeg

932 KB
Loading

bughuntertracker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

colors.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
"standby": "#ded82a",
44
"valid": "#2ade2d",
55
"error": "#de2a2a",
6-
"dev": "#ffffff"
6+
"dev": "#ffffff",
7+
"user": "#000000",
8+
"tier0": "#c6c6c6",
9+
"tier1": "#c8ae99",
10+
"tier2": "#4ad46b",
11+
"tier3": "#3dff66",
12+
"tier4": "#6cff00",
13+
"tier5": "#f7ff00"
714
}

commands/addBugHunter.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const Discord = require("discord.js");
2+
const fs = require("fs");
3+
const Perks = require("../utils/perks.js");
4+
const devsio = require('../utils/devsio.js');
5+
const colors = require("../colors.json");
6+
const botsettings = require("../botsettings.json");
7+
const prefix = botsettings.prefix;
8+
9+
module.exports.run = async (bot, message, args) => {
10+
const member = message.guild.member(message.mentions.members.first() || args[0]);
11+
const confirmationEmbed = new Discord.RichEmbed()
12+
.setAuthor("Reviewer -", bot.avatarURL)
13+
.setTitle("SUCCESS")
14+
.setDescription("This user is now a bug hunter! :tada:")
15+
.setColor(colors.valid)
16+
17+
message.delete()
18+
19+
if(!member) return error(`ERROR: Incorrect usage. You must specify the member to add as a bug hunter. Correct Usage: \`${prefix}addbughunter bug_hunter\``);
20+
21+
devsio.readdevs(devs => {
22+
if(!devs.includes(message.author.id)) return error("ERROR: Missing Permissions. You are not allowed to run this command.")
23+
fs.readFile("./bughuntertracker.json", "utf8", async (err, data) => {
24+
if(err) return console.error(err);
25+
const bughunterArr = await JSON.parse(data);
26+
const bughunter = bughunterArr.find(bughunter => bughunter.id === member.id);
27+
if(!bughunter)
28+
bughunterArr.push({id: member.id, tokens: 0, tier: 0, perks: new Perks()})
29+
else return error("ERROR: This user is already a bug hunter");
30+
const bughunterJSON = JSON.stringify(bughunterArr);
31+
fs.writeFile("./bughuntertracker.json", bughunterJSON, "utf8", err => {
32+
if(err) console.error(err);
33+
});
34+
message.channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
35+
});
36+
});
37+
38+
// Error Handler
39+
40+
function error(errorMessage) {
41+
const errorEmbed = new Discord.RichEmbed()
42+
.setAuthor("Reviewer -", bot.avatarURL)
43+
.setTitle("ERROR")
44+
.setDescription(`${errorMessage}\nBug Hunter Addition process halted. Please run the command again to restart.`)
45+
.setColor(colors.error);
46+
message.channel.send(errorEmbed).then(msg => {
47+
message.delete(0);
48+
msg.delete(10000);
49+
});
50+
}
51+
}
52+
module.exports.help = {
53+
name: "addbughunter",
54+
description:"Adds a bug hunter."
55+
};

commands/buy.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const Discord = require("discord.js");
2+
const fs = require("fs");
3+
const Perks = require("../utils/perks.js")
4+
const colors = require("../colors.json");
5+
const botsettings = require("../botsettings.json");
6+
const storeJSON = require("../store.json");
7+
const prefix = botsettings.prefix;
8+
const bugHunterRoleID = botsettings.roleid_bughunter;
9+
10+
const perksPath = "../utils/Perks/";
11+
12+
/**
13+
*
14+
* @param {Discord.Client} bot
15+
* @param {Discord.TextChannel} channel
16+
*/
17+
module.exports.run = async (bot, message, args) => {
18+
let channel = message.channel;
19+
let member = message.author;
20+
let item = args.slice(0).join(" ");
21+
let storeItems = {};
22+
Object.entries(storeJSON).forEach(([key, val]) => storeItems[key.split("_").map(perk => perk.charAt(0).toUpperCase() + perk.slice(1)).join(" ")] = val);
23+
24+
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.`)
25+
item = item.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
26+
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.`)
27+
28+
const tierColors = [colors.tier0, colors.tier1, colors.tier2, colors.tier3, colors.tier4, colors.tier5]
29+
const tierRomanNumerals = ["I", "II", "III", "IV", "V"]
30+
// Get user info
31+
fs.readFile("./bughuntertracker.json", "utf8", async (err, data) => {
32+
if(err) return console.error(err);
33+
const bugHunterArr = JSON.parse(data);
34+
const bugHunter = bugHunterArr.find(bughunter => bughunter.id === member.id);
35+
if(bugHunter) {
36+
const storeItem = storeItems[item] || storeItems["Color Roles"];
37+
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.`);
38+
try {
39+
if(item.startsWith("Color Roles")) {
40+
const perkUnlockResponse = await buyColorRole(args[2]);
41+
if(perkUnlockResponse !== true) return error(perkUnlockResponse);
42+
} else {
43+
const perk = require(`${perksPath + item}.js`)
44+
const perkUnlockResponse = perk.unlock(channel.guild, bugHunter);
45+
if(perkUnlockResponse !== true) return error(perkUnlockResponse);
46+
}
47+
bugHunter.tokens -= storeItem.tokens;
48+
} catch (err) {
49+
return error(`ERROR: This item has not been implemented: \`(${err})\``)
50+
}
51+
} 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.");
52+
const bugHunterJSON = JSON.stringify(bugHunterArr);
53+
fs.writeFile("./bughuntertracker.json", bugHunterJSON, "utf8", err => {
54+
if(err) {
55+
console.error(err);
56+
return error(`ERROR: Write to database failed. Please send the following message to Whimpers: (${err})`);
57+
}
58+
});
59+
const confirmationEmbed = new Discord.RichEmbed()
60+
.setAuthor("Reviewer -", bot.avatarURL)
61+
.setTitle("SUCCESS")
62+
.setDescription("Your purchase was successfull! :tada:")
63+
.setColor(colors.valid);
64+
channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
65+
});
66+
67+
message.delete(0);
68+
69+
async function buyColorRole(color) {
70+
if(!color) return `ERROR: Incorrect Usage. Please specify a color. Correct usage: \`${prefix}buy Color Roles color\``;
71+
if(!(/^#[0-9A-Fa-f]{6}$/).test(color)) return "ERROR: Color must be in a hex format. Example: #f00ba7";
72+
const bugHunterRole = message.guild.roles.find(r => r.id === bugHunterRoleID);
73+
const colorRole = await channel.guild.createRole({
74+
name: color,
75+
color: color,
76+
position: bugHunterRole.position
77+
})
78+
message.guild.member(member).addRole(colorRole)
79+
return true;
80+
}
81+
82+
// Error Handler
83+
84+
function error(errorMessage) {
85+
const errorEmbed = new Discord.RichEmbed()
86+
.setAuthor("Reviewer -", bot.avatarURL)
87+
.setTitle("ERROR")
88+
.setDescription(`${errorMessage}\nPurchase process halted. Please run the command again to restart.`)
89+
.setColor(colors.error);
90+
channel.send(errorEmbed).then(msg => {
91+
message.delete(0);
92+
msg.delete(10000);
93+
});
94+
}
95+
};
96+
97+
98+
module.exports.help = {
99+
name: "buy",
100+
description:"Purchases a perk from the store."
101+
};

commands/embed.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const Discord = require("discord.js");
2+
const {isBugHunter} = require("../utils/isBugHunter.js")
3+
const botSettings = require("../botsettings.json");
4+
const colors = require("../colors.json");
5+
const prefix = botSettings.prefix;
6+
7+
module.exports.run = async (bot, message, args) => {
8+
message.delete();
9+
10+
if(!(isBugHunter(message.author.id) && isBugHunter(message.author.id).embederUnlocked)) return error(`ERROR: Missing permissions. You do not have the embeder perk unlocked.`)
11+
if(args.length < 1) return error(`ERROR: Incorrect usage. You must specify a message to embed. Correct usage: \`${prefix}embed color message\``);
12+
13+
const colorTester = args[0];
14+
let color;
15+
let msg = args.slice(1).join(" ");
16+
17+
if((/[0-9A-Fa-f]{6}/g).test(colorTester)) {
18+
color = colorTester;
19+
} else {
20+
msg = args.slice(0).join(" ");
21+
}
22+
23+
let embed = new Discord.RichEmbed()
24+
.setTitle(msg)
25+
.setColor(color || colors.info)
26+
.setFooter("- " + message.author.tag)
27+
message.channel.send(embed);
28+
29+
// Error Handler
30+
31+
function error(errorMessage) {
32+
const errorEmbed = new Discord.RichEmbed()
33+
.setAuthor('Reviewer -', bot.avatarURL)
34+
.setTitle("ERROR")
35+
.setDescription(`${errorMessage}\nEmbeder process halted. Please run the command again to restart your report.`)
36+
.setColor(colors.error)
37+
message.channel.send(errorEmbed).then(msg => {
38+
message.delete(0)
39+
msg.delete(5000)
40+
});
41+
}
42+
}
43+
44+
module.exports.help = {
45+
name: "embed",
46+
description: "Creates an embed with specified message"
47+
}

commands/forceAcceptReport.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Discord = require("discord.js");
22
const colors = require("../colors.json");
33
const BugReport = require("../utils/bugReport.js");
44
const devsio = require('../utils/devsio.js');
5+
const {isBugHunter} = require("../utils/isBugHunter.js")
56
const fs = require("fs");
67
const botSettings = require("../botsettings.json")
78
const pending_channelid = botSettings.channelid_pendingbugs;
@@ -65,6 +66,7 @@ module.exports.run = async (bot, message, args) => {
6566
})
6667
message.delete(0);
6768
})
69+
6870
// Error Handler
6971

7072
function error(errorMessage) {

commands/forceDenyReport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Discord = require("discord.js");
22
const colors = require("../colors.json");
33
const BugReport = require("../utils/bugReport.js");
44
const devsio = require('../utils/devsio.js');
5+
const {isBugHunter} = require("../utils/isBugHunter.js")
56
const fs = require("fs");
67
const botSettings = require("../botsettings.json");
78
const pending_channelid = botSettings.channelid_pendingbugs;

commands/giveTokens.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const Discord = require("discord.js");
2+
const fs = require("fs");
3+
const Perks = require("../utils/perks.js");
4+
const devsio = require('../utils/devsio.js');
5+
const colors = require("../colors.json");
6+
const botsettings = require("../botsettings.json");
7+
const prefix = botsettings.prefix;
8+
9+
module.exports.run = async (bot, message, args) => {
10+
const member = message.guild.member(message.mentions.members.first() || args[0]);
11+
const tokens = Number(args[1]);
12+
13+
const confirmationEmbed = new Discord.RichEmbed()
14+
.setAuthor("Reviewer -", bot.avatarURL)
15+
.setTitle("SUCCESS")
16+
.setDescription("Tokens given! :tada:")
17+
.setColor(colors.valid)
18+
19+
message.delete()
20+
21+
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\``);
22+
23+
devsio.readdevs(devs => {
24+
if(!devs.includes(message.author.id)) return error("ERROR: Missing Permissions. You are not allowed to run this command.")
25+
fs.readFile("./bughuntertracker.json", "utf8", (err, data) => {
26+
if(err) return console.error(err);
27+
const bughunterArr = JSON.parse(data);
28+
const bughunter = bughunterArr.find(bughunter => bughunter.id === member.id);
29+
if(!bughunter)
30+
bughunterArr.push({id: member.id, tokens: tokens, tier: 0, perks: new Perks()})
31+
else bughunter.tokens += tokens;
32+
const bughunterJSON = JSON.stringify(bughunterArr);
33+
fs.writeFile("./bughuntertracker.json", bughunterJSON, "utf8", err => {
34+
if(err) console.error(err);
35+
});
36+
message.channel.sendEmbed(confirmationEmbed).then(msg => msg.delete(5000));
37+
});
38+
});
39+
40+
// Error Handler
41+
42+
function error(errorMessage) {
43+
const errorEmbed = new Discord.RichEmbed()
44+
.setAuthor("Reviewer -", bot.avatarURL)
45+
.setTitle("ERROR")
46+
.setDescription(`${errorMessage}\nToken addition process halted. Please run the command again to restart.`)
47+
.setColor(colors.error);
48+
message.channel.send(errorEmbed).then(msg => {
49+
message.delete(0);
50+
msg.delete(10000);
51+
});
52+
}
53+
}
54+
module.exports.help = {
55+
name: "givetokens",
56+
description:"Gives tokens a bug hunter."
57+
};

commands/launch.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const Discord = require('discord.js');
2+
const {isBugHunter} = require("../utils/isBugHunter.js")
3+
const colors = require("../colors.json");
4+
const takeOff = new Discord.Attachment("./assets/takeOff.jpeg", "takeOff.jpeg");
5+
const launchSuccess = new Discord.Attachment("./assets/launchSuccess.gif", "launchSuccess.gif");
6+
const launchFail = new Discord.Attachment("./assets/launchFail.gif", "launchFail.gif");
7+
8+
module.exports.run = async (bot, message, args) => {
9+
const user = message.mentions.users.first() || message.author;
10+
const randomNumber = Math.round(Math.random());
11+
12+
message.delete()
13+
if(!(isBugHunter(message.author.id) && isBugHunter(message.author.id).launcherUnlocked)) return error(`ERROR: Missing permissions. You do not have the launcher perk unlocked.`)
14+
15+
const launchEmbed = new Discord.RichEmbed()
16+
.setAuthor('Reviewer -', bot.avatarURL)
17+
.setTitle('LAUNCH')
18+
19+
if(randomNumber) {
20+
launchEmbed.addField(`${user.username} was launched into space by ${message.author.username}!`, `${user.username}'s rocket flew to space!`);
21+
launchEmbed.attachFile(launchSuccess)
22+
launchEmbed.setImage("attachment://launchSuccess.gif");
23+
launchEmbed.setColor(colors.valid)
24+
} else {
25+
launchEmbed.addField(`${user.username} was launched into space by ${message.author.username}!`, `${user.username}'s rocket blew up!`);
26+
launchEmbed.attachFile(launchFail)
27+
launchEmbed.setImage("attachment://launchFail.gif");
28+
launchEmbed.setColor(colors.error)
29+
}
30+
31+
message.channel.sendEmbed(launchEmbed)
32+
33+
// Error Handler
34+
35+
function error(errorMessage) {
36+
const errorEmbed = new Discord.RichEmbed()
37+
.setAuthor("Reviewer -", bot.avatarURL)
38+
.setTitle("ERROR")
39+
.setDescription(`${errorMessage}\nLauncher process halted. Please run the command again to restart.`)
40+
.setColor(colors.error);
41+
message.channel.send(errorEmbed).then(msg => {
42+
msg.delete(10000);
43+
});
44+
}
45+
}
46+
47+
module.exports.help = {
48+
name: "launch",
49+
description:"Launch someone into space!"
50+
}

0 commit comments

Comments
 (0)