Skip to content
4 changes: 2 additions & 2 deletions modules/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ async function AddPoints(Name, amount)
{
var tribedataraw = await ReadData();
var tribedata = JSON.parse(tribedataraw);
var tribe = tribedata[Name]
var tribe = tribedata.tribes[Name]
tribe.Points += amount;
await WriteData(JSON.stringify(tribedata));
}
async function MinusPoints(Name, amount)
{
var tribedataraw = await ReadData();
var tribedata = JSON.parse(tribedataraw);
var tribe = tribedata[Name]
var tribe = tribedata.tribes[Name]
tribe.Points -= amount;
await WriteData(JSON.stringify(tribedata));
}
Expand Down
75 changes: 75 additions & 0 deletions slash/addPoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable linebreak-style */
const { ReadData, AddPoints } = require("../modules/functions");
require("dotenv").config();

exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
await interaction.deferReply({ ephemeral: true });
// JSON file
var tribedataraw = await ReadData();
var tribedata = JSON.parse(tribedataraw);

// Check if tribe exists in tribedata.
const tribe = interaction.options.get("tribe").value;
if (!tribedata.tribes[tribe]) {
interaction.editReply({ content: "This tribe does not exist.", ephemeral: true });
return;
}

var points = interaction.options.get("points").value;

// If points is negative, return.
if (points < 0) {
interaction.editReply({ content: "You can't add negative points.", ephemeral: true });
return;
}

// Add points to tribe.
await AddPoints(tribe, points);

// Send log to alert channel
const embed = {
"title": `addPoints - ${tribe}`,
"description": `**Tribe:** ${tribe}\n**Points added:** ${points}\n**Added by:** <@${interaction.user.id}>`,
"color": 4690898, // 16711680 = red for moderation logs | 4690898 = pink/purplish for other commands
"timestamp": new Date(),
"footer": {
"icon_url": "https://cdn.discordapp.com/icons/811270187843977236/5a7ac443be8f92675def615e470ac4a6.webp?size=96",
"text": "Hamza's Cult"
}
};

// Send message to alert channel
client.channels.cache.get(process.env.LogChannel).send({ embeds: [embed] });

// Return success message.
interaction.editReply({ content: `Added ${points} point[s] to **${tribe}**.`, ephemeral: true });
};

exports.commandData = {
name: "addpoints",
description: "Add points to a tribe (Tribe Admin only).",
options: [

{
name:"tribe",
description:"Name of the tribe you want to add points to.",
type:3,
required:true
},
{
name:"points",
description:"How many points you want to add.",
type:4,
required:true
}
],
defaultPermission: true,
};

// Set guildOnly to true if you want it to be available on guilds only.
// Otherwise false is global.
exports.conf = {
permLevel: "Cult Admin",
guildOnly: true
};
//Tested
54 changes: 54 additions & 0 deletions slash/leaderboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable linebreak-style */
const { ReadData } = require("../modules/functions");
require("dotenv").config();

exports.run = async (client, interaction) => {
// eslint-disable-line no-unused-vars
// JSON file
var tribedataraw = await ReadData();
var tribedata = JSON.parse(tribedataraw);

tribes = tribedata.tribes
// Sort tribes by points in ascending order
const sortedTribes = Object.entries(tribes)
.sort(([, a], [, b]) => b.Points - a.Points)
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});

const sortedKeys = Object.keys(sortedTribes);


// Create function to conntattonate string
function lbLine(index) {
// If index position is undefined, return nothing
if (sortedKeys[index] === undefined) return "";
return `${index + 1}. ${sortedKeys[index]} - **${tribes[sortedKeys[index]].Points} points**\n`;
}
// Create embed
const embed = {
"title": "Leaderboard",
"description": `${lbLine(0)}` + `${lbLine(1)}` + `${lbLine(2)}` + `${lbLine(3)}` + `${lbLine(4)}` + `${lbLine(5)}` + `${lbLine(6)}` + `${lbLine(7)}` + `${lbLine(8)}` + `${lbLine(9)}`,
"color": 4690898, // 16711680 = red for moderation logs | 4690898 = pink/purplish for other commands
"timestamp": new Date(),
"footer": {
"icon_url": "https://cdn.discordapp.com/icons/811270187843977236/5a7ac443be8f92675def615e470ac4a6.webp?size=96",
"text": "Hamza's Cult"
}
};
// Send leaderboard
interaction.reply({ embeds: [embed] });
};

exports.commandData = {
name: "leaderboard",
description: "Displays top 10 tribes with the most points.",
defaultPermission: true,
};

// Set guildOnly to true if you want it to be available on guilds only.
// Otherwise false is global.
exports.conf = {
permLevel: "User",
guildOnly: true
};

// Tested and working as of 10/10/2021
81 changes: 81 additions & 0 deletions slash/removePoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint-disable linebreak-style */
const { ReadData, MinusPoints } = require("../modules/functions");
require("dotenv").config();

exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
await interaction.deferReply({ ephemeral: true });
// JSON file
var tribedataraw = await ReadData();
var tribedata = JSON.parse(tribedataraw);

// Check if tribe exists in tribedata.
const tribe = interaction.options.get("tribe").value;
if (!tribedata.tribes[tribe]) {
interaction.editReply({ content: "This tribe does not exist.", ephemeral: true });
return;
}

var points = interaction.options.get("points").value;

// If points is negative, return.
if (points < 0) {
interaction.editReply({ content: "You can't remove negative points.", ephemeral: true });
return;
}

// If tribe has less points than points to remove, return.
if (tribedata.tribes[tribe].Points < points) {
interaction.editReply({ content: `This tribe only has ${tribedata.tribes[tribe].Points} points.`, ephemeral: true });
return;
}

// Remove points to tribe.
await MinusPoints(tribe, points);

// Send log to alert channel
const embed = {
"title": `removePoints - ${tribe}`,
"description": `**Tribe:** ${tribe}\n**Points removed:** ${points}\n**Removed by:** <@${interaction.user.id}>`,
"color": 4690898, // 16711680 = red for moderation logs | 4690898 = pink/purplish for other commands
"timestamp": new Date(),
"footer": {
"icon_url": "https://cdn.discordapp.com/icons/811270187843977236/5a7ac443be8f92675def615e470ac4a6.webp?size=96",
"text": "Hamza's Cult"
}
};

// Send message to alert channel
client.channels.cache.get(process.env.LogChannel).send({ embeds: [embed] });

// Return success message.
interaction.editReply({ content: `Removed ${points} point[s] to **${tribe}**.`, ephemeral: true });
};

exports.commandData = {
name: "removepoints",
description: "Removes points from a tribe (Tribe Admin only).",
options: [

{
name:"tribe",
description:"Name of the tribe you want to remove points to.",
type:3,
required:true
},
{
name:"points",
description:"How many points you want to remove.",
type:4,
required:true
}
],
defaultPermission: true,
};

// Set guildOnly to true if you want it to be available on guilds only.
// Otherwise false is global.
exports.conf = {
permLevel: "Cult Admin",
guildOnly: true
};
//Tested