Skip to content

Commit

Permalink
update project_description and rolespermoverride to ts and tested is …
Browse files Browse the repository at this point in the history
…pass
  • Loading branch information
Bigbugman committed Oct 20, 2023
2 parents da9b795 + 9267c68 commit cdae960
Show file tree
Hide file tree
Showing 97 changed files with 34,651 additions and 9,189 deletions.
Binary file added .DS_Store
Binary file not shown.
12 changes: 7 additions & 5 deletions commands/24game.js → commands/24game.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";

const MAX = 9;

module.exports = {
export default {
data: new SlashCommandBuilder()
.setName("24")
.setDescription("Generates 4 random numbers from 0 to 9!"),
async execute(interaction) {
const resultNums = [];


async execute(interaction: ChatInputCommandInteraction) {
const resultNums: number[] = [];

for (let i = 0; i < 4; i++) {
const random = Math.round(Math.random() * MAX);
Expand All @@ -18,4 +20,4 @@ module.exports = {

await interaction.reply(output);
},
};
};
51 changes: 37 additions & 14 deletions commands/24parser.js → commands/24parser.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const math = require("mathjs");
const { Util } = require("discord.js");
//@ts-check
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
import * as math from 'mathjs';


const illegalPhraseRegexes = [/`/g, /@/g];

const isIllegalCharactersPresent = (expression) => {
/**
*
* @param {string} expression
* @returns
*/
const isIllegalCharactersPresent = (expression: string) => {
return illegalPhraseRegexes.some((regex) => regex.test(expression));
};

const tryCompileAndEvaluate = (eqnString) => {
/**
*
* @param {string} eqnString
* @returns
*/
const tryCompileAndEvaluate = (eqnString: string) => {
try {
const equationObj = math.compile(eqnString);
if (!equationObj) {
throw Error;
}

const equationOutcome = equationObj.evaluate();
/** @type {number} */
const equationOutcome: number = equationObj.evaluate();

return {
success: true,
Expand All @@ -30,15 +41,20 @@ const tryCompileAndEvaluate = (eqnString) => {
}
};

const evaluate = (equationString, target) => {
/**
*
* @param {string} equationString
* @param {number} target
* @returns
*/
const evaluate = (equationString: string, target: number) => {
if (isIllegalCharactersPresent(equationString)) {
return {
success: false,
message: "Could not compile. Illegal input detected.",
ephemeral: true,
};
}

const evaluationOutcome = tryCompileAndEvaluate(equationString);
if (!evaluationOutcome.success) {
return {
Expand Down Expand Up @@ -71,7 +87,7 @@ const evaluate = (equationString, target) => {
};
};

module.exports = {
export default {
data: new SlashCommandBuilder()
.setName("24parse")
.setDescription("Checks whether an equation evaluates to 24 (or a number input)!")
Expand All @@ -81,8 +97,14 @@ module.exports = {
.addNumberOption((option) =>
option.setName("target").setDescription("Target for your equation").setRequired(false),
),
async execute(interaction) {
const equationStr = interaction.options.getString("equation");

/**
* @async
* @param {ChatInputCommandInteraction} interaction
* @returns
*/
async execute(interaction: ChatInputCommandInteraction) {
const equationStr = interaction.options.getString("equation", true);
const target = interaction.options.getNumber("target") || 24;

const { success, message, ephemeral } = evaluate(equationStr, target);
Expand All @@ -91,8 +113,9 @@ module.exports = {
const output = `${emoji} ${message}`;

await interaction.reply({
content: Util.removeMentions(output),
content: output,
ephemeral,
allowedMentions: {},
});
},
};
};
16 changes: 12 additions & 4 deletions commands/24plus.js → commands/24plus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
//@ts-check
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";

const MAX = 11;
const MAX_TARGET = 99;
Expand All @@ -9,8 +10,15 @@ module.exports = {
.setDescription(
"Generates 4 random numbers from 1 to 12 and a random target from 1 to 100.",
),
async execute(interaction) {
const resultNums = [];

/**
* @async
* @param {ChatInputCommandInteraction} interaction
* @returns
*/
async execute(interaction: ChatInputCommandInteraction) {
/** @type {number[]} */
const resultNums: number[] = [];

for (let i = 0; i < 4; i++) {
const random = Math.round(Math.random() * MAX) + 1;
Expand All @@ -23,4 +31,4 @@ module.exports = {

await interaction.reply(output);
},
};
};
111 changes: 73 additions & 38 deletions commands/admin-standup.js → commands/admin-standup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed, MessageButton, Permissions } = require("discord.js");
const paginationEmbed = require("discordjs-button-pagination");
// @ts-check
import { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction } from "discord.js";
import { Pagination } from "pagination.djs";

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -24,12 +24,15 @@ module.exports = {
),
),

async execute(interaction) {
const standupDB = global.standupDBGlobal;

async execute(interaction: ChatInputCommandInteraction) {
const standupDB = (global as any).standupDBGlobal;
const TEAM_DIRECTOR_ROLE_ID = "921348676692107274";
if (!interaction.inCachedGuild()) return;

if (
!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR) &&
!interaction.member._roles.includes(TEAM_DIRECTOR_ROLE_ID)
!interaction.member.permissions.has(PermissionFlagsBits.Administrator) &&
!interaction.member.roles.cache.has(TEAM_DIRECTOR_ROLE_ID)
) {
return await interaction.reply({
content: "You do not have permission to execute this command.",
Expand All @@ -41,19 +44,26 @@ module.exports = {
let sendmsg = "";

try {
const team = await interaction.options.getMentionable("teamrole");
const numDaysToRetrieve = (await interaction.options.getInteger("days")) ?? 7;
const team = interaction.options.getMentionable("teamrole", true);
const teamRoleID = team.id;
const role = await interaction.guild.roles.fetch(teamRoleID);
if (!role) return;
/*eslint-disable */
var roleMembers = [...role.members?.values()];
var roleMembers = [...role.members.values()];
/* eslint-enable */

const ON_BREAK_ID = "1036905668352942090";
roleMembers = roleMembers.filter((rm) => !rm._roles.includes(ON_BREAK_ID));
roleMembers = roleMembers.filter((rm) => !rm.roles.cache.has(ON_BREAK_ID));

if (!interaction.channel) return;
const thisTeamId = interaction.channel.parentId;
let thisTeamStandups = await standupDB.getStandups(thisTeamId, numDaysToRetrieve);
const numDaysToRetrieve = (interaction.options.getInteger("days")) ?? 7;

const roleNames = {};
/** @type {{ user_id: string; standup_content: string; }[]} */
let thisTeamStandups: { user_id: string; standup_content: string; }[] = await standupDB.getStandups(thisTeamId, numDaysToRetrieve);

/** @type {Record<string, string>} */
const roleNames: Record<string, string> = {};
roleMembers.forEach((el) => {
const author = el.user.username;
/* let author = el.nickname;
Expand All @@ -67,17 +77,21 @@ module.exports = {
Object.keys(roleNames).includes(st.user_id),
);

const standupDone = [];
const standupEmbeded = [];
/** @type {string[]} */
const standupDone: string[] = [];

/** @type {string[]} */
const standupEmbeded: string[] = [];

// add all standups
thisTeamStandups.forEach((standUp) => {
standupDone.push(standUp.user_id);
standupEmbeded.push(
"**" +
`${roleNames[standUp.user_id]}` +
"**" +
"\n" +
standUp.standup_content,
`${roleNames[standUp.user_id]}` +
"**" +
"\n" +
standUp.standup_content,
);
sendmsg +=
"**" +
Expand All @@ -88,7 +102,8 @@ module.exports = {
sendmsg += "\n";
});

const notDone = [];
/** @type {string[]} */
const notDone: string[] = [];

roleMembers.forEach((el) => {
const id = el.user.id;
Expand All @@ -100,11 +115,12 @@ module.exports = {
let notDoneUsersString = "";
notDoneUsersString = notDone.map((el) => `<@${el}>`).join(", ");

const embedList = [];
/** @type {EmbedBuilder[]} */
const embedList: EmbedBuilder[] = [];
if (notDone.length == 0) {
standupEmbeded.forEach((el) => {
embedList.push(
new MessageEmbed()
new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
el + "\n\n" + "_Everyone has done their standup_\n",
Expand All @@ -114,38 +130,55 @@ module.exports = {
} else {
standupEmbeded.forEach((el) => {
embedList.push(
new MessageEmbed()
new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
el +
"\n\n" +
"_These users have not done their standup:_\n" +
notDoneUsersString,
"\n\n" +
"_These users have not done their standup:_\n" +
notDoneUsersString,
),
);
});
}

if (thisTeamStandups.length == 0) {
const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle("Standups (" + role.name + ")")
.setDescription(
"No standups recorded\n\n" +
"_These users have not done their standup:_\n" +
notDoneUsersString,
"_These users have not done their standup:_\n" +
notDoneUsersString,
);
return await interaction.reply({ embeds: [embed] });
}

const buttonList = [
new MessageButton()
.setCustomId("previousbtn")
.setLabel("Previous")
.setStyle("DANGER"),
new MessageButton().setCustomId("nextbtn").setLabel("Next").setStyle("SUCCESS"),
];
// const buttonList = [
// new ButtonBuilder()
// .setCustomId("previousbtn")
// .setLabel("Previous")
// .setStyle(ButtonStyle.Danger),
// new ButtonBuilder().setCustomId("nextbtn").setLabel("Next").setStyle(ButtonStyle.Success),
// ];

paginationEmbed(interaction, embedList, buttonList);
// may need to tweak this as necessary
const pagination = new Pagination(interaction, {
firstEmoji: '⏮', // First button emoji
prevEmoji: '◀️', // Previous button emoji
nextEmoji: '▶️', // Next button emoji
lastEmoji: '⏭', // Last button emoji
prevLabel: "Previous",
nextLabel: "Next",
});

// /** @type {Record<string, ButtonBuilder>} */
// const buttons: Record<string, ButtonBuilder> = buttonList.reduce((_, button, i) => Object.assign(String(i), button), {});
pagination.addEmbeds(embedList);
// pagination.setButtons(buttons);
await pagination.reply();

// depdendency on v13 helper functions - DEPRECATED
// paginationEmbed(interaction, embedList, buttonList);

// sendmsg += "\n" + "These users have not done their standup:\n" + notDoneUsersString;
// await interaction.reply(sendmsg);
Expand All @@ -154,6 +187,8 @@ module.exports = {
await interaction.reply({ content: sendmsg, ephemeral: true });
}
}

return Promise.resolve();
/* else if (interaction.options.getSubcommand() === "resetstandups") {
try {
await standupDB.deleteAllStandups();
Expand All @@ -169,4 +204,4 @@ module.exports = {
}
}*/
},
};
};
Loading

0 comments on commit cdae960

Please sign in to comment.