Skip to content

Commit

Permalink
Merge branch 'nate-goldsborough' of https://github.com/Antares-Networ…
Browse files Browse the repository at this point in the history
…k/CSSC-Bot into nate-goldsborough
  • Loading branch information
nathen418 committed Sep 1, 2022
2 parents 9bb583f + 470445a commit 498c739
Show file tree
Hide file tree
Showing 21 changed files with 799 additions and 660 deletions.
64 changes: 36 additions & 28 deletions commands/owner/createRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,42 @@ import { createRoles } from "../../rolesOps";
import chalk from "chalk";

export default {
name: "createRoles",
category: "owner",
description: "Creates roles if they do not exist in the server",
slash: true,
testOnly: false,
guildOnly: true,
requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"],
ownerOnly: true,
name: "createRoles",
category: "owner",
description: "Creates roles if they do not exist in the server",
slash: true,
testOnly: false,
guildOnly: true,
requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"],
ownerOnly: true,

callback: async ({ interaction }) => {
console.log(chalk.green("Creating roles...\nCopy and paste the following output into your .env file"));
console.log(chalk.red("------------------------------------------------------"));
// Create the roles
createRoles(interaction.guild!, "class");
createRoles(interaction.guild!, "staff");
createRoles(interaction.guild!, "year");
interaction.reply({
content: "Roles created!",
ephemeral: true,
});
callback: async ({ interaction }) => {
console.log(
chalk.green(
"Creating roles...\nCopy and paste the following output into your .env file"
)
);
console.log(
chalk.red("------------------------------------------------------")
);
// Create the roles
createRoles(interaction.guild!, "class");
createRoles(interaction.guild!, "staff");
createRoles(interaction.guild!, "year");
interaction.reply({
content: "Roles created!",
ephemeral: true,
});

// Log the command usage
console.log(
chalk.blue(
`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow(
interaction.guild?.name
)}`
)
);
},
// Log the command usage
console.log(
chalk.blue(
`${chalk.green(`[COMMAND]`)} ${chalk.yellow(
interaction.user.tag
)} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow(
interaction.guild?.name
)}`
)
);
},
} as ICommand;
34 changes: 18 additions & 16 deletions commands/owner/csClassPoll.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { MessageEmbed, MessageActionRow, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
import {
MessageEmbed,
MessageActionRow,
MessageSelectMenu,
MessageSelectOptionData,
} from "discord.js";
import chalk from "chalk";
import { ICommand } from "wokcommands";
import classModel from "../../models/classModel";
import { checkForRoles } from "../../rolesOps";

export interface Class {
CODE: string,
TITLE: string,
INFO: string,
ROLE_NAME: string,
ROLE_ID: string,
UUID: string,
CODE: string;
TITLE: string;
INFO: string;
ROLE_NAME: string;
ROLE_ID: string;
UUID: string;
}

export default {
Expand All @@ -34,7 +39,7 @@ export default {
let classes: Class[] = await classModel.find({}).sort({ CODE: 1 });
const class_chunks = split_list(classes, 25);

let rows:MessageActionRow[] = [];
let rows: MessageActionRow[] = [];
for (let index = 0; index < class_chunks.length; index++) {
const menu = new MessageSelectMenu();
menu.setCustomId(`csClassPoll+${index}`);
Expand All @@ -50,8 +55,7 @@ export default {
rows.push(row);
}


const row_chunks = split_list(rows, 5)
const row_chunks = split_list(rows, 5);
for (let index = 0; index < row_chunks.length; index++) {
if (index == 0) {
// Define embeds used in this command
Expand Down Expand Up @@ -91,12 +95,11 @@ export default {

// Splits any size list into lists of at most `max_list_len`
function split_list(list: Array<any>, max_list_len: number) {
let class_chunks = []
let class_chunks = [];
for (let i = 0; i < list.length; i += max_list_len) {
class_chunks.push(list.slice(i, i + max_list_len))

class_chunks.push(list.slice(i, i + max_list_len));
}
return class_chunks
return class_chunks;
}

// consumes a Class and returns Message Selec tOption data
Expand All @@ -105,6 +108,5 @@ function create_option_from_class(_class: Class): MessageSelectOptionData {
label: _class.CODE,
value: _class.CODE,
description: _class.TITLE,
}
};
}

44 changes: 30 additions & 14 deletions commands/owner/say.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,41 @@ export default {
type: DiscordJS.Constants.ApplicationCommandOptionTypes.STRING,
required: true,
},
{
name: "channel",
description: "The channel to say the thing in",
type: DiscordJS.Constants.ApplicationCommandOptionTypes.CHANNEL,
required: false,
}
],
{
name: "channel",
description: "The channel to say the thing in",
type: DiscordJS.Constants.ApplicationCommandOptionTypes.CHANNEL,
required: false,
},
],

callback: ({ interaction }) => {
const content = interaction.options.getString("content") as string;
const channel = interaction.options.getChannel("channel") as TextChannel || interaction.channel as TextChannel;
const channel =
(interaction.options.getChannel("channel") as TextChannel) ||
(interaction.channel as TextChannel);
if (!content) {
interaction.reply({ content: "You need to provide a content to say", ephemeral: true });
return;
interaction.reply({
content: "You need to provide a content to say",
ephemeral: true,
});
return;
}
channel.send(content);
interaction.reply({ content: `Message sent in <#${channel.id}>`, ephemeral: true });
interaction.reply({
content: `Message sent in <#${channel.id}>`,
ephemeral: true,
});

// Log the command usage
console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/say`)} command in ${chalk.yellow(interaction.guild?.name)}`));
}
} as ICommand;
console.log(
chalk.blue(
`${chalk.green(`[COMMAND]`)} ${chalk.yellow(
interaction.user.tag
)} used the ${chalk.green(`/say`)} command in ${chalk.yellow(
interaction.guild?.name
)}`
)
);
},
} as ICommand;
130 changes: 70 additions & 60 deletions commands/owner/staffPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,78 @@ import { ICommand } from "wokcommands";
import { checkForRoles } from "../../rolesOps";

export default {
name: "staffPoll",
category: "owner",
description: "Posts the College Staff Poll",
slash: true,
testOnly: false,
guildOnly: true,
requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"],
ownerOnly: true,
name: "staffPoll",
category: "owner",
description: "Posts the College Staff Poll",
slash: true,
testOnly: false,
guildOnly: true,
requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"],
ownerOnly: true,

callback: async ({ client, interaction: msgInt }) => {
// Define embeds used in this command
const infoEmbed = new MessageEmbed()
.setTitle("Choose a role")
.setColor("#0099ff")
.setDescription("Select the option with your current occupation at UWM.")
.setFooter({
text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`,
iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg",
});
callback: async ({ client, interaction: msgInt }) => {
// Define embeds used in this command
const infoEmbed = new MessageEmbed()
.setTitle("Choose a role")
.setColor("#0099ff")
.setDescription("Select the option with your current occupation at UWM.")
.setFooter({
text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`,
iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg",
});

// Create row one of the buttons for the poll
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("collegeStaffPoll")
.setPlaceholder("Select an option")
.addOptions(
{
label: "Tutor",
value: "Tutor",
},
{
label: "SI Leader",
value: "Sileader",
},
{
label: "TA",
value: "Ta",
},
{
label: "Professor",
value: "Professor",
},
{
label: "Student Employee",
value: "Studentemployee",
},
{
label: "None",
value: "None",
description: "Clear all staff roles",
}
)
);
// Create row one of the buttons for the poll
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("collegeStaffPoll")
.setPlaceholder("Select an option")
.addOptions(
{
label: "Tutor",
value: "Tutor",
},
{
label: "SI Leader",
value: "Sileader",
},
{
label: "TA",
value: "Ta",
},
{
label: "Professor",
value: "Professor",
},
{
label: "Student Employee",
value: "Studentemployee",
},
{
label: "None",
value: "None",
description: "Clear all staff roles",
}
)
);

// Send the embed and message component rows
if (!checkForRoles(msgInt.guild!)) {
msgInt.reply("Please run the `/createRoles` command in this server to create the necessary roles for this poll!");
} else {
msgInt.reply({ embeds: [infoEmbed], components: [row] });
}
// Send the embed and message component rows
if (!checkForRoles(msgInt.guild!)) {
msgInt.reply(
"Please run the `/createRoles` command in this server to create the necessary roles for this poll!"
);
} else {
msgInt.reply({ embeds: [infoEmbed], components: [row] });
}

// Log the command usage
console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(msgInt.user.tag)} used the ${chalk.green(`/staffPoll`)} command in ${chalk.yellow(msgInt.guild?.name)}`));
},
// Log the command usage
console.log(
chalk.blue(
`${chalk.green(`[COMMAND]`)} ${chalk.yellow(
msgInt.user.tag
)} used the ${chalk.green(`/staffPoll`)} command in ${chalk.yellow(
msgInt.guild?.name
)}`
)
);
},
} as ICommand;
Loading

0 comments on commit 498c739

Please sign in to comment.