Compare commits
3 Commits
1e99783d0e
...
eee43d2976
Author | SHA1 | Date | |
---|---|---|---|
eee43d2976 | |||
819ca2fd52 | |||
02863e7c1d |
185
src/index.js
185
src/index.js
@ -1,5 +1,5 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import {Client, IntentsBitField} from 'discord.js';
|
import {Client, IntentsBitField, EmbedBuilder, MessageManager} from 'discord.js';
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
|
|
||||||
const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READWRITE,(err) => {
|
const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READWRITE,(err) => {
|
||||||
@ -10,6 +10,7 @@ const db = new sqlite3.Database("./db/employeescoreboard.db", sqlite3.OPEN_READW
|
|||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
IntentsBitField.Flags.Guilds,
|
IntentsBitField.Flags.Guilds,
|
||||||
@ -19,6 +20,7 @@ const client = new Client({
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client
|
||||||
|
|
||||||
client.on('ready', (c) => {
|
client.on('ready', (c) => {
|
||||||
console.log('The Swog is prepared.');
|
console.log('The Swog is prepared.');
|
||||||
@ -26,12 +28,23 @@ client.on('ready', (c) => {
|
|||||||
//Chat commands are handled here
|
//Chat commands are handled here
|
||||||
client.on('interactionCreate', async(interaction) => {
|
client.on('interactionCreate', async(interaction) => {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
let isManager = await interaction.member.roles.cache.some(role => role.name === 'Manager');
|
||||||
if (interaction.commandName === 'croak') {
|
if (interaction.commandName === 'croak') {
|
||||||
interaction.reply('Croak!');
|
interaction.reply('Croak!');
|
||||||
}
|
};
|
||||||
|
|
||||||
if (interaction.commandName === 'gear') {
|
if (interaction.commandName == 'companyid') {
|
||||||
|
|
||||||
|
let employeeCard = await EmployeeCardEmbed(interaction.options.get('employee').value);
|
||||||
|
if (typeof employeeCard === 'string') {
|
||||||
|
interaction.reply(employeeCard);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interaction.reply({embeds: [employeeCard]});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (interaction.commandName === 'gear' && isManager) {
|
||||||
const addRemove = interaction.options.get('addremove').value;
|
const addRemove = interaction.options.get('addremove').value;
|
||||||
const gearType = interaction.options.get('geartype').value;
|
const gearType = interaction.options.get('geartype').value;
|
||||||
const employee = interaction.options.get('employee').value;
|
const employee = interaction.options.get('employee').value;
|
||||||
@ -40,10 +53,12 @@ client.on('interactionCreate', async(interaction) => {
|
|||||||
interaction.reply(`Added a gear to ${employee}`)
|
interaction.reply(`Added a gear to ${employee}`)
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} else if (interaction.commandName === 'gear' && !isManager) {
|
||||||
|
interaction.reply("You aren't a manager! Get back to work.")
|
||||||
|
};
|
||||||
|
|
||||||
if (interaction.commandName === 'employee') {
|
if (interaction.commandName === 'employee' && isManager) {
|
||||||
const hireFirePromote = interaction.options.get('hire-fire-promote').value;
|
const hireFirePromote = interaction.options.get('hire-fire').value;
|
||||||
const employeeName = interaction.options.get('employee-name').value;
|
const employeeName = interaction.options.get('employee-name').value;
|
||||||
if (hireFirePromote == 'hire') {
|
if (hireFirePromote == 'hire') {
|
||||||
CreateEmployee(employeeName);
|
CreateEmployee(employeeName);
|
||||||
@ -51,23 +66,40 @@ client.on('interactionCreate', async(interaction) => {
|
|||||||
}
|
}
|
||||||
if (hireFirePromote == 'fire') {
|
if (hireFirePromote == 'fire') {
|
||||||
DeleteEmployee(employeeName);
|
DeleteEmployee(employeeName);
|
||||||
|
interaction.reply(`Fired ${employeeName}`)
|
||||||
}
|
}
|
||||||
}
|
} else if (interaction.commandName === 'employee' && !isManager) {
|
||||||
|
interaction.reply("You aren't a manager! Get back to work.")
|
||||||
|
};
|
||||||
|
|
||||||
if (interaction.commandName === 'promote') {
|
if (interaction.commandName === 'promote' && isManager) {
|
||||||
const employeeName = interaction.options.get('employee-name').value;
|
const employeeName = interaction.options.get('employee-name').value;
|
||||||
const rank = interaction.options.get('rank').value;
|
const rank = interaction.options.get('rank').value;
|
||||||
PromoteEmployee(employeeName, rank);
|
PromoteEmployee(employeeName, rank);
|
||||||
interaction.reply(`Changed ${employeeName}\'s rank to ${rank}`);
|
interaction.reply(`Changed ${employeeName}\'s rank to ${rank}`);
|
||||||
}
|
} else if (interaction.commandName === 'promote' && !isManager) {
|
||||||
|
interaction.reply("You aren't a manager! Get back to work.")
|
||||||
|
};
|
||||||
|
|
||||||
if (interaction.commandName === 'scoreboard') {
|
if (interaction.commandName === 'rename' && isManager) {
|
||||||
|
RenameEmployee(interaction.options.get('old-name').value,interaction.options.get('new-name').value)
|
||||||
|
interaction.reply(`Renamed ${interaction.options.get('old-name').value} to ${interaction.options.get('new-name').value}`)
|
||||||
|
} else if (interaction.commandName === 'promote' && !isManager) {
|
||||||
|
interaction.reply("You aren't a manager! Get back to work.")
|
||||||
|
};
|
||||||
|
|
||||||
|
if (interaction.commandName === 'scoreboard' && isManager) {
|
||||||
const updateOrDisplay = interaction.options.get('update-display').value;
|
const updateOrDisplay = interaction.options.get('update-display').value;
|
||||||
|
const gearchannel = client.channels.cache.get('1255024866797682779');
|
||||||
|
let scoreBoardMessage = await BuildScoreboard("Beastboss");
|
||||||
|
scoreBoardMessage += await BuildScoreboard("Manager");
|
||||||
|
scoreBoardMessage += await BuildScoreboard("Muscle");
|
||||||
|
scoreBoardMessage += await BuildScoreboard("Moneymaker");
|
||||||
|
scoreBoardMessage += await BuildScoreboard("Mystic");
|
||||||
|
scoreBoardMessage += await BuildScoreboard("Intern");
|
||||||
if (updateOrDisplay == 'display') {
|
if (updateOrDisplay == 'display') {
|
||||||
|
|
||||||
const gearchannel = client.channels.cache.get('1306669146804715693');
|
|
||||||
let scoreBoardMessage = await BuildScoreboard();
|
|
||||||
console.log("Scoreboard goes here: " + scoreBoardMessage);
|
console.log("Scoreboard goes here: " + scoreBoardMessage);
|
||||||
|
|
||||||
if (scoreBoardMessage != "") {
|
if (scoreBoardMessage != "") {
|
||||||
gearchannel.send(scoreBoardMessage);
|
gearchannel.send(scoreBoardMessage);
|
||||||
interaction.reply("Displaying Scoreboard");
|
interaction.reply("Displaying Scoreboard");
|
||||||
@ -76,51 +108,150 @@ client.on('interactionCreate', async(interaction) => {
|
|||||||
console.log("Something went wrong when building the scoreboard.");
|
console.log("Something went wrong when building the scoreboard.");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
if (updateOrDisplay == 'update') {
|
||||||
|
const messagesInGearchannel = await gearchannel.messages.fetch()
|
||||||
|
const gearMessage = await messagesInGearchannel.find(msg => msg.author.id === '1306647733490290809')
|
||||||
|
|
||||||
|
if (gearMessage === undefined) {
|
||||||
|
interaction.reply("Could not find a message to update, did you remember to display it first?");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gearMessage.edit(scoreBoardMessage);
|
||||||
|
interaction.reply("Updated scoreboard.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (interaction.commandName === 'scoreboard' && !isManager) {
|
||||||
|
interaction.reply("You aren't a manager! Get back to work.")
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
function CreateEmployee(Name) {
|
function CreateEmployee(Name) {
|
||||||
db.run(`INSERT INTO Employees (name) VALUES (\'${Name}\')`);
|
db.run(`INSERT INTO Employees (name, coppergear) VALUES (\'${Name}\', 0)`);
|
||||||
};
|
};
|
||||||
|
|
||||||
function DeleteEmployee(Name) {
|
function DeleteEmployee(Name) {
|
||||||
db.run(`DELETE FROM Employees WHERE name = \'${Name}\'`);
|
db.run(`DELETE FROM Employees WHERE name = \'${Name}\'`);
|
||||||
};
|
};
|
||||||
|
|
||||||
function PromoteEmployee(Name, rank) {
|
function PromoteEmployee(Name, rank) {
|
||||||
db.run(`UPDATE Employees SET rank = \'${rank}\' WHERE name = \'${Name}\'`)
|
db.run(`UPDATE Employees SET rank = \'${rank}\' WHERE name = \'${Name}\'`)
|
||||||
};
|
};
|
||||||
|
|
||||||
function AddGear(Type,Employee) {
|
function AddGear(Type,Employee) {
|
||||||
if (Type != "coppergear" | "silvergear" | "goldgear") return
|
if (Type == "copper" || Type == "silver" || Type == "gold" || Type == "purple"){
|
||||||
|
Type += "gear";
|
||||||
|
}
|
||||||
|
if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return
|
||||||
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `)
|
db.run(`UPDATE Employees SET ${Type} = ${Type} + 1 WHERE name = \'${Employee}\' `)
|
||||||
};
|
};
|
||||||
|
function RemoveGear(Type, Employee) {
|
||||||
|
if (Type != "coppergear" && Type != "silvergear" && Type != "goldgear" && Type != "purplegear") return
|
||||||
|
db.run(`UPDATE Employees SET ${Type} = ${Type} - 1 WHERE name = \'${Employee}\'`)
|
||||||
|
};
|
||||||
|
function RenameEmployee(oldName, newName) {
|
||||||
|
db.run(`UPDATE Employees SET name = \'${newName}\' WHERE name = \'${oldName}\'`);
|
||||||
|
};
|
||||||
|
|
||||||
function BuildScoreboard() {
|
function EmployeeCardEmbed(employeeName) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let messageContent = "";
|
db.get(`SELECT name, rank, coppergear, silvergear, goldgear, purplegear, copperswog, silverswog, goldswog, purpleswog FROM Employees WHERE name = ?`,[employeeName], (err, character) => {
|
||||||
db.each('SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees', (err, character) => {
|
if (err != null) {
|
||||||
|
console.log(err.message)
|
||||||
|
resolve("Something went wrong when fetching employee info");
|
||||||
|
};
|
||||||
|
if(character === undefined) {
|
||||||
|
console.log("No data returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (character !== undefined){
|
||||||
|
let copperGearString = " ";
|
||||||
|
console.log(character.coppergear);
|
||||||
|
for (let i = 0; i < character.coppergear; i++) {
|
||||||
|
copperGearString += "<:coppergear:1308166341622235179>";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let silverGearString = " ";
|
||||||
|
console.log(character.silvergear);
|
||||||
|
for (let i = 0; i < character.silvergear; i++) {
|
||||||
|
silverGearString += ":gear:";
|
||||||
|
};
|
||||||
|
|
||||||
|
let goldGearString = " ";
|
||||||
|
console.log(character.goldgear);
|
||||||
|
for(let i = 0; i < character.goldgear; i++) {
|
||||||
|
goldGearString += "<:goldgear:1308166365550481499>";
|
||||||
|
};
|
||||||
|
let purplegearString =" ";
|
||||||
|
console.log(character.purplegear);
|
||||||
|
for(let i = 0; i< character.purplegear; i++) {
|
||||||
|
purplegearString += "<:purplegear:1308166392864051250>";
|
||||||
|
};
|
||||||
|
|
||||||
|
const employeeCard = new EmbedBuilder()
|
||||||
|
.setColor(0x388E3C)
|
||||||
|
.setTitle(employeeName)
|
||||||
|
.setDescription(character.rank)
|
||||||
|
.addFields(
|
||||||
|
{name:`Copper`, value: copperGearString, inline: true},
|
||||||
|
{name:'Silver', value: silverGearString, inline: true},
|
||||||
|
{name:'Purple', value: purplegearString, inline: true},
|
||||||
|
)
|
||||||
|
.addFields(
|
||||||
|
{name:'Gold', value: goldGearString, inline: true},
|
||||||
|
)
|
||||||
|
.setFooter({text: 'ID Issued by Gearbeast Inc. Do not copy.'});
|
||||||
|
resolve(employeeCard);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve("Something went wrong when fetching employee information");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function BuildScoreboard(rank) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
let messageContent = `# ${rank} \n`;
|
||||||
|
|
||||||
|
db.each(`SELECT name, rank, coppergear, silvergear, goldgear, purplegear FROM Employees WHERE rank = ?`, [rank], (err, character) => {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
console.log(err.message);
|
console.log(err.message);
|
||||||
};
|
};
|
||||||
|
|
||||||
let copperGearString = "";
|
let copperGearString = "";
|
||||||
console.log(character.coppergear);
|
//console.log(character.coppergear);
|
||||||
|
if (character.coppergear >0) {copperGearString += "\n## "}
|
||||||
for (let i = 0; i < character.coppergear; i++) {
|
for (let i = 0; i < character.coppergear; i++) {
|
||||||
copperGearString += ":coppergear:"
|
copperGearString += "<:coppergear:1308166341622235179>";
|
||||||
};
|
};
|
||||||
|
|
||||||
let silverGearString = "";
|
let silverGearString = "";
|
||||||
console.log(character.silvergear);
|
//console.log(character.silvergear);
|
||||||
|
if (character.silvergear > 0) {silverGearString += "\n## "}
|
||||||
for (let i = 0; i < character.silvergear; i++) {
|
for (let i = 0; i < character.silvergear; i++) {
|
||||||
silvergearstring += ":gear:"
|
silverGearString += ":gear:";
|
||||||
}
|
};
|
||||||
|
|
||||||
let goldGearString = "";
|
let goldGearString = "";
|
||||||
messageContent += `**${character.name}** \n ##${copperGearString} \n`;
|
//console.log(character.goldgear);
|
||||||
|
if(character.goldgear > 0) {goldGearString += "\n## "};
|
||||||
|
for(let i = 0; i < character.goldgear; i++) {
|
||||||
|
goldGearString += "<:goldgear:1308166365550481499>";
|
||||||
|
};
|
||||||
|
let purplegearString ="";
|
||||||
|
//console.log(character.purplegear);
|
||||||
|
if(character.purplegear > 0) {purplegearString += "\n## "};
|
||||||
|
for(let i = 0; i< character.purplegear; i++) {
|
||||||
|
purplegearString += "<:purplegear:1308166392864051250>";
|
||||||
|
};
|
||||||
|
|
||||||
|
messageContent += `**${character.name}** ${goldGearString} ${purplegearString} ${silverGearString} ${copperGearString} \n`;
|
||||||
}, () => {resolve(messageContent); });
|
}, () => {resolve(messageContent); });
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
@ -10,6 +10,18 @@ const commands = [
|
|||||||
name: 'croak',
|
name: 'croak',
|
||||||
description: 'Makes Sir Hornsworth Croak!',
|
description: 'Makes Sir Hornsworth Croak!',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'companyid',
|
||||||
|
description: 'Request a Comapny ID of a specific employee',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'employee',
|
||||||
|
description: 'Who do you want the id of?',
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'gear',
|
name: 'gear',
|
||||||
description: 'Add or remove a gear to an employee',
|
description: 'Add or remove a gear to an employee',
|
||||||
@ -39,7 +51,7 @@ const commands = [
|
|||||||
description: 'Hire or Fire an employee',
|
description: 'Hire or Fire an employee',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'hire-fire-promote',
|
name: 'hire-fire',
|
||||||
description: 'Hiring or Firing?',
|
description: 'Hiring or Firing?',
|
||||||
type: ApplicationCommandOptionType.String,
|
type: ApplicationCommandOptionType.String,
|
||||||
required: true,
|
required: true,
|
||||||
@ -70,6 +82,24 @@ const commands = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'rename',
|
||||||
|
description: 'Rename an Employee',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'old-name',
|
||||||
|
description: 'The old name of the employee',
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'new-name',
|
||||||
|
description: 'The new name of the employee',
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'scoreboard',
|
name: 'scoreboard',
|
||||||
description: 'Related to the scoreboard',
|
description: 'Related to the scoreboard',
|
||||||
|
Loading…
Reference in New Issue
Block a user