Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ti redos #14

Open
wants to merge 5 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions events/discord/ready.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
const register = require('../../utils/slashsync');
const register = require("../../utils/slashsync");
module.exports = async (client) => {
let servercount = await client.guilds.cache
let mcount = 0;
client.guilds.cache.forEach((guild) => {
mcount += guild.memberCount
})
await register(client, client.register_arr.map((command) => ({
name: command.name,
description: command.description,
options: command.options,
type: 'CHAT_INPUT'
})), {
debug: true
let servercount = await client.guilds.cache;
let mcount = 0;
client.guilds.cache.forEach((guild) => {
mcount += guild.memberCount;
});
await register(
client,
client.register_arr.map((command) => ({
name: command.name,
description: command.description,
options: command.options,
type: "CHAT_INPUT",
})),
{
debug: false,
}
);

console.log(`[ / | Slash Command ] - ✅ Loaded all slash commands!`)
console.log(`[ / | Slash Command ] - ✅ Loaded all slash commands!`);
console.log(`[STATUS] ${client.user.tag} is now online!`);
// const activities = [`Your Giveaways`, `${mcount} users`];
// setInterval(() => {
Expand Down
99 changes: 99 additions & 0 deletions slash/ti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const Discord = require("discord.js");
const messages = require("../utils/message")("ti");
const ms = require("ms");

module.exports = {
name: "ti",
description: "Post a TI redo",

options: [
{
name: "ti",
description: "What TI do you need to post?",
type: "STRING",
required: true,
},
{
name: "duration",
description: "How long should the TI trade last? (e.g., 15m, 1h, 30s)",
type: "STRING",
required: false,
},
],

run: async (client, interaction) => {
// List of roles that are allowed to perform the action
const allowedRoles = {
edops: "1267542964188479560",
admin: "1266465782863368265",
};

// Check if the member has one of the allowed roles
const userRole = interaction.member.roles.cache.find((r) =>
Object.keys(allowedRoles).includes(r.name)
);

// If the member doesn't have any of the allowed roles
if (!userRole) {
return interaction.reply({
content:
"❌ | You need to have the appropriate ed-ops or Admin role to start a TI trade.",
ephemeral: true,
});
}

// Dynamically use the channel where the command is run
const tradeChannel = interaction.channel;

// Ensure the channel is a valid text channel
if (!tradeChannel || tradeChannel.type !== "GUILD_TEXT") {
return interaction.reply({
content: "❌ | The channel is not a valid text channel.",
ephemeral: true,
});
}

const tradePrize = interaction.options.getString("ti");
const userDurationInput = interaction.options.getString("duration");

function getDuration(input) {
const defaultDuration = ms("20m");
if (input) {
const parsedDuration = ms(input);
if (parsedDuration) {
return parsedDuration;
} else {
console.error("Invalid duration format. Defaulting to 20 minutes.");
}
}
return defaultDuration;
}

const tradeDuration = getDuration(userDurationInput);
const tradeWinnerCount = 1;

await interaction.deferReply({ ephemeral: true });

// Make sure giveawaysManager is initialized
if (!client.giveawaysManager) {
return interaction.reply({
content: "❌ | Giveaways Manager is not set up properly.",
ephemeral: true,
});
}

// Start giveaway
client.giveawaysManager.start(tradeChannel, {
duration: tradeDuration,
prize: tradePrize,
hostedBy: `<@${interaction.user.id}>`,
winnerCount: parseInt(tradeWinnerCount),
messages,
});

interaction.editReply({
content: `You dropped a TI redo in ${tradeChannel}!`,
ephemeral: true,
});
},
};
52 changes: 35 additions & 17 deletions slash/trade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Discord = require("discord.js");
const messages = require("../utils/message");
const ms = require("ms");

module.exports = {
name: "trade",
description: "🎉 Drop a shift!",
Expand All @@ -16,19 +17,18 @@ module.exports = {
],

run: async (client, interaction) => {
// List of roles that are allowed to perform the action
// List of roles that are allowed to perform the action, using role ID as key
const allowedRoles = {
web: "1266459443852345475",
data: "1266459414878228598",
cyber: "1266459384779640893",
"1266460843525148774": "1266459443852345475", // web role ID -> channel ID
"1266460754639327263": "1266459414878228598", // data role ID -> channel ID
"1266460877108936875": "1266459384779640893", // cyber role ID -> channel ID
};

// Check if the member has one of the allowed roles
const userRole = interaction.member.roles.cache.find((r) =>
Object.keys(allowedRoles).includes(r.name)
// Find the role the user has and match it to the allowedRoles object by ID
const userRole = interaction.member.roles.cache.find(
(r) => Object.keys(allowedRoles).includes(r.id) // Check if the user's role ID matches the allowed role IDs
);

// If the member doesn't have any of the allowed roles
if (!userRole) {
return interaction.reply({
content:
Expand All @@ -37,27 +37,45 @@ module.exports = {
});
}

const channelId = allowedRoles[userRole.name];
const tradeChannel = client.channels.cache.get(channelId);
// Get the corresponding channel ID based on the user's role ID
const channelId = allowedRoles[userRole.id];

if (!channelId) {
return interaction.reply({
content:
"❌ | Could not determine the correct trade channel. Please contact an admin.",
ephemeral: true,
});
}

// Fetch the trade channel based on the mapped channel ID
let tradeChannel = await client.channels.fetch(channelId).catch((err) => {
console.log(`❌ Could not fetch channel ${channelId}:`, err);
});

if (!tradeChannel) {
return interaction.reply({
content:
"❌ | Could not find a valid text channel. Please contact an admin.",
ephemeral: true,
});
}

const tradeDuration = ms(1000 * 60 * 45);
const tradeDuration = ms("45m");
const tradeWinnerCount = 1;
const tradePrize = interaction.options.getString("shift");

await interaction.deferReply({ ephemeral: true });

// start giveaway
// Start giveaway
client.giveawaysManager.start(tradeChannel, {
// The giveaway duration
duration: ms(tradeDuration),
// The giveaway prize
duration: tradeDuration,
prize: tradePrize,
// The giveaway Host
hostedBy: `<@${interaction.user.id}>`,
// The giveaway winner count
winnerCount: parseInt(tradeWinnerCount),
messages,
});

interaction.editReply({
content: `You dropped your shift in ${tradeChannel}!`,
ephemeral: true,
Expand Down
40 changes: 22 additions & 18 deletions utils/message.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
const config = require("../config.json");
module.exports = {
giveaway:
(config.everyoneMention ? `<@&${993594724965421206}>\n\n` : "") +
"\n🎉 **SHIFT TRADE!** 🎉",
giveawayEnded:
(config.everyoneMention ? `<@&${993594724965421206}>\n\n` : "") +
"ℹ️ **SHIFT TRADE PERIOD ENDED.** ℹ️",
drawing: `Ends: **{timestamp}**`,
color: "#012D3D",
inviteToParticipate: `React with ✋ to participate!`,
winMessage:
"Congratulations, {winners}! You won the **{this.prize}** shift from {this.hostedBy}! Please make sure {this.hostedBy} transfers the shift(s) in ClockTower accordingly.",
embedFooter: `{this.winnerCount} winner`,
noWinner:
"Hello {this.hostedBy}. \n This trade shift period has ended and nobody claimed your shift. If you'd like to try again, you can restart the command.",
hostedBy: "Hosted by: {this.hostedBy}.",
winners: "winner",
endedAt: "Ended at",
module.exports = (commandType) => {
const isTI = commandType === "ti";

return {
giveaway: isTI ? "🎉 **TI REDO!** 🎉" : "🎉 **SHIFT TRADE!** 🎉",
giveawayEnded: isTI
? "ℹ️ **TI REDO PERIOD ENDED.** ℹ️"
: "ℹ️ **SHIFT TRADE PERIOD ENDED.** ℹ️",
drawing: `Ends: **{timestamp}**`,
color: "#012D3D",
inviteToParticipate: `React with ✋ to participate!`,
winMessage: isTI
? "Congratulations, {winners}! You won the **{this.prize}** TI! {this.hostedBy} will add the shift in ClockTower or coordinate timing as needed!"
: "Congratulations, {winners}! You won the **{this.prize}** shift from {this.hostedBy}! Please make sure {this.hostedBy} transfers the shift(s) in ClockTower accordingly.",
embedFooter: `{this.winnerCount} winner`,
noWinner: isTI
? "Hello {this.hostedBy}. \n This TI redo period has ended and nobody claimed the TI. If you'd like to try again, you can restart the command."
: "Hello {this.hostedBy}. \n This trade shift period has ended and nobody claimed your shift. If you'd like to try again, you can restart the command.",
hostedBy: "Hosted by: {this.hostedBy}.",
winners: "winner",
endedAt: "Ended at",
};
};