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

button handler, wouldyou regen button #27

Merged
merged 3 commits into from
Sep 6, 2022
Merged
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
75 changes: 75 additions & 0 deletions src/buttons/rather_useful.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
} = require('discord.js');
const guildLang = require('../util/Models/guildModel');

module.exports = {
data: {
name: 'rather_useful',
description: 'rather useful',
},
async execute(interaction, client) {
guildLang
.findOne({ guildID: interaction.guild.id })
.then(async (result) => {
const { Rather } = await require(`../languages/${result.language}.json`);
const { Useless_Powers, Useful_Powers } = await require(`../data/power-${result.language}.json`);
const button = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('Invite')
.setStyle(5)
.setEmoji('🤖')
.setURL(
'https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=274878294080&scope=bot%20applications.commands',
),
);
const newButton = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('New Round')
.setStyle(1)
.setEmoji('🔄')
.setCustomId('rather_useful'),
);
let rbutton;
if (Math.round(Math.random() * 9) < 3) {
rbutton = [button, newButton];
} else rbutton = [newButton];
{
let usefulpower1 = Useful_Powers[Math.floor(Math.random() * Useful_Powers.length)];
let usefulpower2 = Useful_Powers[Math.floor(Math.random() * Useful_Powers.length)];

let ratherembed = new EmbedBuilder()
.setColor('#0598F6')
.addFields(
{
name: Rather.embed.usefulname,
value: `> 1️⃣ ${usefulpower1}`,
inline: false,
},
{
name: Rather.embed.usefulname2,
value: `> 2️⃣ ${usefulpower2}`,
inline: false,
},
)
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp();

let message = await interaction
.reply({
embeds: [ratherembed],
components: rbutton,
fetchReply: true,
})
.catch((err) => {
return;
});
}
});
},
};
156 changes: 156 additions & 0 deletions src/buttons/rather_useful_voting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
} = require('discord.js');
const guildLang = require('../util/Models/guildModel');

module.exports = {
data: {
name: 'rather_useful_voting',
description: 'rather useful voting',
},
async execute(interaction, client) {
guildLang
.findOne({ guildID: interaction.guild.id })
.then(async (result) => {
const { Rather } = await require(`../languages/${result.language}.json`);
const { Useless_Powers, Useful_Powers } = await require(`../data/power-${result.language}.json`);
const button = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('Invite')
.setStyle(5)
.setEmoji('🤖')
.setURL(
'https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=274878294080&scope=bot%20applications.commands',
),
);
const newButton = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('New Round')
.setStyle(1)
.setEmoji('🔄')
.setCustomId('rather_useful_voting'),
);
let rbutton;
if (Math.round(Math.random() * 9) < 3) {
rbutton = [button, newButton];
} else rbutton = [newButton];
{
let usefulpower1 = Useful_Powers[Math.floor(Math.random() * Useful_Powers.length)];
let usefulpower2 = Useful_Powers[Math.floor(Math.random() * Useful_Powers.length)];

let ratherembed = new EmbedBuilder()
.setColor('#0598F6')
.addFields(
{
name: Rather.embed.usefulname,
value: `> 1️⃣ ${usefulpower1}`,
inline: false,
},
{
name: Rather.embed.usefulname2,
value: `> 2️⃣ ${usefulpower2}`,
inline: false,
},
)
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp();

let message = await interaction
.reply({
embeds: [ratherembed],
fetchReply: true,
components: rbutton,
})
.catch((err) => {
return;
});
try {
await message.react('1️⃣');
await message.react('2️⃣');
const filter = (reaction) => reaction.emoji.name == '1️⃣' || reaction.emoji.name == '2️⃣';

const collector = message.createReactionCollector({
filter,
time: 20000,
});
collector.on('collect', async () => {});

collector.on('end', async () => {
if (
message.reactions.cache.get('1️⃣').count - 1
> message.reactions.cache.get('2️⃣').count - 1
) {
ratherembed = new EmbedBuilder()
.setColor('#0598F6')
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp()
.addFields({
name: Rather.embed.thispower,
value: `> 1️⃣ ${usefulpower1}`,
inline: false,
});
} else if (
message.reactions.cache.get('1️⃣').count - 1
< message.reactions.cache.get('2️⃣').count - 1
) {
ratherembed = new EmbedBuilder()
.setColor('#0598F6')
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp()
.addFields({
name: Rather.embed.thispower,
value: `> 2️⃣ ${usefulpower2}`,
inline: false,
});
} else {
ratherembed = new EmbedBuilder()
.setColor('#ffffff')
.addFields(
{
name: Rather.embed.usefulname,
value: `> 1️⃣ ${usefulpower1}`,
inline: false,
},
{
name: Rather.embed.usefulname2,
value: `> 2️⃣ ${usefulpower2}`,
inline: false,
},
)
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp();
}

try {
await message.reactions.removeAll();
} catch (error) {}
await interaction
.editReply({
embeds: [ratherembed],
components: rbutton || [],
})
.catch((err) => {
return;
});

collector.stop();
});
} catch (error) {}
}
});
},
};
75 changes: 75 additions & 0 deletions src/buttons/rather_useless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
} = require('discord.js');
const guildLang = require('../util/Models/guildModel');

module.exports = {
data: {
name: 'rather_useless',
description: 'rather useless',
},
async execute(interaction, client) {
guildLang
.findOne({ guildID: interaction.guild.id })
.then(async (result) => {
const { Rather } = await require(`../languages/${result.language}.json`);
const { Useless_Powers, Useful_Powers } = await require(`../data/power-${result.language}.json`);
const button = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('Invite')
.setStyle(5)
.setEmoji('🤖')
.setURL(
'https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=274878294080&scope=bot%20applications.commands',
),
);
const newButton = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('New Round')
.setStyle(1)
.setEmoji('🔄')
.setCustomId('rather_useless'),
);
let rbutton;
if (Math.round(Math.random() * 9) < 3) {
rbutton = [button, newButton];
} else rbutton = [newButton];
{
let uselesspower1 = Useless_Powers[Math.floor(Math.random() * Useless_Powers.length)];
let uselesspower2 = Useless_Powers[Math.floor(Math.random() * Useless_Powers.length)];

let ratherembed = new EmbedBuilder()
.setColor('#F00505')
.addFields(
{
name: Rather.embed.uselessname,
value: `> 1️⃣ ${uselesspower1}`,
inline: false,
},
{
name: Rather.embed.uselessname2,
value: `> 2️⃣ ${uselesspower2}`,
inline: false,
},
)
.setFooter({
text: `${Rather.embed.footer}`,
iconURL: client.user.avatarURL(),
})
.setTimestamp();

let message = await interaction
.reply({
embeds: [ratherembed],
components: rbutton,
fetchReply: true,
})
.catch((err) => {
return;
});
}
});
},
};
Loading