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

Quality of life update #61

Merged
merged 26 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1030655
Add questions
mezotv Feb 9, 2023
6eba6c2
Rather.js update
mezotv Feb 11, 2023
38e1dee
Add images and canvas command
mezotv Feb 13, 2023
310cb47
Fix bug + language support
mezotv Feb 13, 2023
d4f2e8d
Add more questions
mezotv Feb 15, 2023
0aebea1
Added text resize
mezotv Feb 15, 2023
4854293
Add custom strings
mezotv Feb 15, 2023
70b08fc
Finish new rather command
mezotv Feb 21, 2023
4b2a278
Created settings.js
forgetfulskybro Feb 23, 2023
091d2a9
Fix settings command and translation
mezotv Feb 23, 2023
c764547
Fixed emojis
forgetfulskybro Feb 23, 2023
6750bec
Merge branch 'quality-of-life-update' of https://github.com/Would-You…
forgetfulskybro Feb 23, 2023
c5fe522
Adds never have I ever mode
mezotv Feb 23, 2023
8b951c5
Deleted translations for welcome and dailyMsgs
forgetfulskybro Feb 23, 2023
f77ded4
Merge branch 'quality-of-life-update' of https://github.com/Would-You…
forgetfulskybro Feb 23, 2023
4efeace
More settings (unfinished)
mezotv Feb 23, 2023
4fc9435
Fixed embed
forgetfulskybro Feb 24, 2023
7e74dd3
Feat: emit command, user ping
mezotv Feb 24, 2023
12fc5c6
Add more wwyd questions
mezotv Mar 1, 2023
22ed1cb
Improve either.js
mezotv Mar 4, 2023
c0a8c74
Merge branch 'main' of https://github.com/Would-You-Bot/Would-You int…
mezotv Mar 4, 2023
fa9630a
Resolve conflicts
mezotv Mar 4, 2023
f45ec24
Add either.js class
mezotv Mar 10, 2023
f0fc19f
Add replay and vote cooldown
mezotv Mar 11, 2023
0102b49
String + Either update
mezotv Mar 11, 2023
2e7d843
Update info.js
mezotv Mar 12, 2023
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
Prev Previous commit
Next Next commit
Add replay and vote cooldown
  • Loading branch information
mezotv committed Mar 11, 2023
commit f0fc19f9bbefa407e4f7c191a390c8b974f6d59b
93 changes: 93 additions & 0 deletions src/buttons/replayCooldown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const { ButtonBuilder, ActionRowBuilder, EmbedBuilder } = require("discord.js");
const modalObject = {
title: "Would You Replay Cooldown",
custom_id: "replaymodal",
components: [
{
type: 1,
components: [
{
type: 4,
style: 1,
custom_id: "input",
label: "Provide a replay cooldown in milliseconds",
},
],
},
],
};

function isNumericRegex(str) {
return /^[0-9]+$/.test(str); // regex for extra 0,00000002% speeds :trol:
}

module.exports = {
data: {
name: "replayCooldown",
description: "Daily Message Toggle",
},
async execute(interaction, client, guildDb) {
const { Settings } = await require(`../languages/${guildDb.language}.json`);
interaction.showModal(modalObject);
interaction
.awaitModalSubmit({
filter: (mInter) => mInter.customId === modalObject.custom_id,
time: 60000,
})
.then(async (modalInteraction) => {
const value = modalInteraction.components[0].components[0].value;

if (guildDb.replayCooldown === value)
return await modalInteraction.reply({
ephemeral: true,
content: Settings.replaySame,
});
if (isNumericRegex(value) === false)
return await modalInteraction.reply({
ephemeral: true,
content: Settings.cooldownInvalid,
});

const generalMsg = new EmbedBuilder()
.setTitle(Settings.embed.generalTitle)
.setDescription(
`${Settings.embed.voteCooldown}: ${
guildDb.voteCooldown
? `${guildDb.voteCooldown}`
: `<:x_:1077962443013238814>`
}\n${Settings.embed.replayCooldown}: ${
guildDb.replayCooldown
? `${value}`
: `<:x_:1077962443013238814>`
}\n`
)
.setColor("#0598F6")
.setFooter({
text: Settings.embed.footer,
iconURL: client.user.avatarURL(),
});

const generalButtons = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("voteCooldown")
.setLabel(Settings.button.voteCooldown)
.setStyle(guildDb.voteCooldown ? "Success" : "Secondary"),
new ButtonBuilder()
.setCustomId("replayCooldown")
.setLabel(Settings.button.replayCooldown)
.setStyle(guildDb.replayCooldown ? "Success" : "Secondary")
);

await client.database.updateGuild(interaction.guild.id, {
replayCooldown: value,
});

return modalInteraction.update({
content: null,
embeds: [generalMsg],
components: [generalButtons],
ephemeral: true,
});
});
},
};
93 changes: 93 additions & 0 deletions src/buttons/voteCooldown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const { ButtonBuilder, ActionRowBuilder, EmbedBuilder } = require("discord.js");
const modalObject = {
title: "Would You Vote Cooldown",
custom_id: "votemodal",
components: [
{
type: 1,
components: [
{
type: 4,
style: 1,
custom_id: "input",
label: "Provide a vote cooldown in milliseconds",
},
],
},
],
};

function isNumericRegex(str) {
return /^[0-9]+$/.test(str);
}

module.exports = {
data: {
name: "voteCooldown",
description: "Vote Cooldown",
},
async execute(interaction, client, guildDb) {
const { Settings } = await require(`../languages/${guildDb.language}.json`);
interaction.showModal(modalObject);
interaction
.awaitModalSubmit({
filter: (mInter) => mInter.customId === modalObject.custom_id,
time: 60000,
})
.then(async (modalInteraction) => {
const value = modalInteraction.components[0].components[0].value;

if (guildDb.voteCooldown === value)
return await modalInteraction.reply({
ephemeral: true,
content: Settings.voteSame,
});
if (isNumericRegex(value) === false)
return await modalInteraction.reply({
ephemeral: true,
content: Settings.cooldownInvalid,
});

const generalMsg = new EmbedBuilder()
.setTitle(Settings.embed.generalTitle)
.setDescription(
`${Settings.embed.voteCooldown}: ${
guildDb.voteCooldown
? `${value}`
: `<:x_:1077962443013238814>`
}\n${Settings.embed.replayCooldown}: ${
guildDb.replayCooldown
? `${guildDb.replayCooldown}`
: `<:x_:1077962443013238814>`
}\n`
)
.setColor("#0598F6")
.setFooter({
text: Settings.embed.footer,
iconURL: client.user.avatarURL(),
});

const generalButtons = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("voteCooldown")
.setLabel(Settings.button.voteCooldown)
.setStyle(guildDb.voteCooldown ? "Success" : "Secondary"),
new ButtonBuilder()
.setCustomId("replayCooldown")
.setLabel(Settings.button.replayCooldown)
.setStyle(guildDb.replayCooldown ? "Success" : "Secondary")
);

await client.database.updateGuild(interaction.guild.id, {
voteCooldown: value,
});

return modalInteraction.update({
content: null,
embeds: [generalMsg],
components: [generalButtons],
ephemeral: true,
});
});
},
};
20 changes: 8 additions & 12 deletions src/commands/either.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
SlashCommandBuilder,
AttachmentBuilder
} = require('discord.js');
const {Either} = require("../util/generateEither")
const Either = require("../util/generateEither")
const guildModel = require('../util/Models/guildModel');

module.exports = {
Expand Down Expand Up @@ -34,26 +34,22 @@ module.exports = {
*/
async execute(interaction, client, guildDb) {
const eitherImage = new Either()
.setVotes(["https://cdn.discordapp.com/avatars/981649513427111957/af5f8264403034530bba73ba6c2492d9.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512"], ["https://cdn.discordapp.com/avatars/981649513427111957/af5f8264403034530bba73ba6c2492d9.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512", "https://cdn.discordapp.com/avatars/347077478726238228/3b77f755fa8e66fd75d1e2d3fb8b1611.webp?size=512"])
.setLanguage(guildDb.language)
.setLanguage(guildDb.language)
.setVotes(["https://cdn.discordapp.com/avatars/981649513427111957/af5f8264403034530bba73ba6c2492d9.webp?size=512"], ["https://cdn.discordapp.com/avatars/981649513427111957/af5f8264403034530bba73ba6c2492d9.webp?size=512"])


if (!interaction.options.getString('first')) {
eitherImage.addText("Sus")
eitherImage.addText("Sus","1")
} else {
eitherImage.addText(interaction.options.getString('first').length > 48 ? interaction.options.getString('first').substring(0, 48).trim() + '...' : interaction.options.getString('first'));
eitherImage.addText(interaction.options.getString('first').length > 48 ? interaction.options.getString('first').substring(0, 48).trim() + '...' : interaction.options.getString('first'));
}
if (!interaction.options.getString('second')) {
eitherImage.addText("Sus 2")
eitherImage.addText("Sus 2", "s")
} else {
eitherImage.addText(interaction.options.getString('second').length > 48 ? interaction.options.getString('second').substring(0, 48).trim() + '...' : interaction.options.getString('second'));
}

eitherImage.build().then((img) => {
attachment = new AttachmentBuilder(img,
{
name: "wouldyou-card.png",
})
})
attachment = new AttachmentBuilder(await eitherImage.build(), { name: 'wouldyoubot-either.png' })

interaction
.reply({
Expand Down
53 changes: 21 additions & 32 deletions src/commands/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,27 @@ module.exports = {
interaction.reply({ embeds: [dailyMsgs], components: [dailyButtons, dailyButtons2], ephemeral: true }).catch(() => { })
break;

case "general":
const generalMsg = new EmbedBuilder()
.setTitle(Settings.embed.dailyTitle)
.setDescription(`${Settings.embed.dailyMsg}: ${guildDb.dailyMsg ? `<:check:1077962440815411241>` : `<:x_:1077962443013238814>`}\n${Settings.embed.dailyChannel}: ${guildDb.dailyChannel ? `<#${guildDb.dailyChannel}>` : `<:x_:1077962443013238814>`}\n${Settings.embed.dailyRole}: ${guildDb.dailyRole ? `<@&${guildDb.dailyRole}>` : `<:x_:1077962443013238814>`}\n${Settings.embed.dailyTimezone}: ${guildDb.dailyTimezone}\n`)
.setColor("#0598F6")
.setFooter({ text: Settings.embed.footer, iconURL: client.user.avatarURL(), })

const generalButtons = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("dailyMsg")
.setLabel(Settings.button.dailyMsg)
.setStyle(guildDb.dailyMsg ? "Success" : "Secondary"),
new ButtonBuilder()
.setCustomId("dailyChannel")
.setLabel(Settings.button.dailyChannel)
.setStyle(guildDb.dailyChannel ? "Success" : "Secondary"),
), generalButtons2 = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("dailyTimezone")
.setLabel(Settings.button.dailyTimezone)
.setStyle("Primary")
.setEmoji("🌍"),
new ButtonBuilder()
.setCustomId("dailyRole")
.setLabel(Settings.button.dailyRole)
.setStyle(guildDb.dailyRole ? "Success" : "Secondary"),
)

interaction.reply({ embeds: [generalMsg], components: [generalButtons, generalButtons2], ephemeral: true }).catch(() => { })
break;
case "general":
const generalMsg = new EmbedBuilder()
.setTitle(Settings.embed.generalTitle)
.setDescription(`${Settings.embed.voteCooldown}: ${guildDb.voteCooldown ? `${guildDb.voteCooldown}` : `<:x_:1077962443013238814>`}\n${Settings.embed.replayCooldown}: ${guildDb.replayCooldown ? `${guildDb.replayCooldown}` : `<:x_:1077962443013238814>`}\n`)
.setColor("#0598F6")
.setFooter({ text: Settings.embed.footer, iconURL: client.user.avatarURL(), })

const generalButtons = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("voteCooldown")
.setLabel(Settings.button.voteCooldown)
.setStyle(guildDb.voteCooldown ? "Success" : "Secondary"),
new ButtonBuilder()
.setCustomId("replayCooldown")
.setLabel(Settings.button.replayCooldown)
.setStyle(guildDb.replayCooldown ? "Success" : "Secondary"),
)

interaction.reply({ embeds: [generalMsg], components: [generalButtons], ephemeral: true }).catch(() => { })
break;

case "welcomes":
const welcomes = new EmbedBuilder()
Expand Down
8 changes: 8 additions & 0 deletions src/languages/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@
"errorInvalid": "Provided timezone was invalid, you can pick a valid timezone from this [Time Zone Picker](https://kevinnovak.github.io/Time-Zone-Picker/)",
"dailyChannel": "Select a channel where you want Daily Messages to be!",
"dailyRole": "Select a role that you want to be pinged in Daily Messages!",
"replaySame": "The provided replay cooldown is the same cooldown that is already set. Make sure to choose a different cooldown.",
"voteSame": "The provided vote cooldown is the same cooldown that is already set. Make sure to choose a different cooldown.",
"cooldownInvalid": "Provided cooldown was invalid. Make sure the cooldown only includes numbers!",
"embed": {
"generalTitle": "Would You - Daily Messages",
"voteCooldown": "Vote Cooldown",
"replayCooldown": "Replay Cooldown",
"dailyTitle": "Would You - Daily Messages",
"dailyMsg": "**Enabled**",
"dailyRole": "**Role**",
Expand All @@ -227,6 +233,8 @@
"dailyRole": "Set Role",
"dailyTimezone": "Set Timezone",
"dailyMsg": "Toggle Daily Messages",
"voteCooldown": "Set Vote Cooldown",
"replayCooldown": "Set Replay Cooldown",
"welcomeChannel": "Set Channel",
"welcome": "Toggle Welcomes",
"welcomePing": "Toggle User Ping"
Expand Down
4 changes: 4 additions & 0 deletions src/util/Models/guildModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const guildProfile = new Schema(
type: Number,
default: 30000,
},
voteCooldown: {
type: Number,
default: 25000,
},
botJoined: {
type: Number,
},
Expand Down
28 changes: 11 additions & 17 deletions src/util/generateEither.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const Canvas = require("@napi-rs/canvas");
module.exports = class Either {
constructor(client) {
this.c = client;
}
class Either {
constructor() {}

/**
*
Expand All @@ -16,7 +14,8 @@ module.exports = class Either {
throw new Error("Expected rows array instead got " + typeof song);
}
this.rowOne = rowOne;
this.rowTwo = rowTwo
this.rowTwo = rowTwo;
return this;
}

/**
Expand All @@ -30,6 +29,7 @@ module.exports = class Either {
throw new Error("Expected language instead got " + typeof language);
}
this.language = language;
return this;
}

/**
Expand All @@ -40,16 +40,9 @@ module.exports = class Either {
*/

addText(text1, text2) {
if (!text1 || typeof text1 !== "string") {
throw new TypeError("Expected text1 string instead got " + typeof text1);
}
if (!text2 || typeof text2 !== "string") {
throw new TypeError(
"Expected text string instead got " + typeof background
);
}
this.text1 = text1;
this.text2 = text2;
return this;
}

/**
Expand Down Expand Up @@ -92,11 +85,11 @@ module.exports = class Either {

ctx.font = `bold ${fontsize1 || "25"}px sans-serif`;
ctx.fillStyle = "#000000";
ctx.fillText(text1, 140, 156);
ctx.fillText(this.text1, 140, 156);

ctx.font = `bold ${fontsize2 || "25"}px sans-serif`;
ctx.fillStyle = "#000000";
ctx.fillText(text2, 140, 240);
ctx.fillText(this.text2, 140, 240);

var rad = 15;

Expand Down Expand Up @@ -154,6 +147,7 @@ module.exports = class Either {
pos1 -= rad;
}

return canvasObject.encode("png");
return canvas.encode("png");
}
}
};
module.exports = Either;