-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
130 lines (108 loc) · 5.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const { Client, GatewayIntentBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const config = require('./config.json');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions]
});
const suggestionChannelId = config.suggestionChannelId;
const TOKEN = config.TOKEN;
const approverRoleId = config.approverRoleId;
const userVotes = {};
client.once('ready', () => {
console.log('Bot is online!');
console.log('Code by Wick Studio');
console.log('discord.gg/wicks');
});
client.on('messageCreate', message => {
if (message.channel.id === suggestionChannelId) {
const messageContent = message.content;
if (!messageContent.trim()) {
console.log('تم ارسال اقتراح جديد.');
return;
}
const suggestionEmbed = new EmbedBuilder()
.setColor(0xFF0000)
.setTitle('📝 اقتراح جديد')
.setDescription(`**الاقتراح
\n\n:**\n\`\`\`${messageContent}\`\`\``)
.setTimestamp()
.setFooter({ text: `تم الارسال بواسطة : ${message.author.tag}` })
.setThumbnail(message.author.displayAvatarURL())
.addFields(
{ name: 'الحالة', value: '⏳ قيد الانتظار', inline: true },
{ name: 'الدعم', value: '<:p_arrow_up:1213552453375754380> 0 | <:p_arrow_down:1213552445859299390> 0', inline: true }
);
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`accept_${message.author.id}`)
.setLabel(' مقبولة ')
.setEmoji('1213717029756862485')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(`reject_${message.author.id}`)
.setLabel(' مرفوضة ')
.setEmoji('1213717047830126692')
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId('upvote')
.setLabel(' مع ')
.setEmoji('1213552453375754380')
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId('downvote')
.setLabel(' ضد ')
.setEmoji('1213552445859299390')
.setStyle(ButtonStyle.Secondary)
);
message.channel.send({ embeds: [suggestionEmbed], components: [row] })
.then(() => message.delete())
.catch(console.error);
}
});
client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
const messageId = interaction.message.id;
const userId = interaction.user.id;
if (interaction.customId.startsWith('accept') || interaction.customId.startsWith('reject')) {
const roleId = approverRoleId;
if (!interaction.member.roles.cache.has(roleId)) {
return interaction.reply({ content: 'ليس لديك صلاحية لاستخدام هذا الزر.', ephemeral: true });
}
const modal = new ModalBuilder()
.setCustomId(`response-modal-${interaction.customId}`)
.setTitle('Response');
const reasonInput = new TextInputBuilder()
.setCustomId('reason')
.setLabel('Reason')
.setStyle(TextInputStyle.Paragraph);
const actionRow = new ActionRowBuilder().addComponents(reasonInput);
modal.addComponents(actionRow);
await interaction.showModal(modal);
} else if (interaction.customId === 'upvote' || interaction.customId === 'downvote') {
if (!userVotes[messageId]) userVotes[messageId] = new Set();
if (userVotes[messageId].has(userId)) {
return interaction.reply({ content: 'لقد قمت بالتصويت على هذا الاقتراح بالفعل.', ephemeral: true });
}
userVotes[messageId].add(userId);
const originalEmbed = interaction.message.embeds[0];
const fields = originalEmbed.fields;
// Extract upvotes and downvotes values from the voteText
const upvotesText = fields[1].value.split('|')[0].trim().split(' ')[1].trim();
const downvotesText = fields[1].value.split('|')[1].trim().split(' ')[1].trim();
// Convert upvotes and downvotes to integers
let upvotes = parseInt(upvotesText);
let downvotes = parseInt(downvotesText);
// Check if upvotes and downvotes are valid numbers, if not, set them to 0
if (isNaN(upvotes)) upvotes = 0;
if (isNaN(downvotes)) downvotes = 0;
// Increment upvotes or downvotes based on the interaction customId
if (interaction.customId === 'upvote') upvotes++;
if (interaction.customId === 'downvote') downvotes++;
// Update the embed with the new upvotes and downvotes values
const updatedEmbed = new EmbedBuilder(originalEmbed)
.spliceFields(1, 1, { name: 'الدعم', value: ` <:p_arrow_up:1213552453375754380> ${upvotes} | <:p_arrow_down:1213552445859299390> ${downvotes}`, inline: true });
// Send the updated embed with interaction components
await interaction.update({ embeds: [updatedEmbed], components: interaction.message.components });
}
});
client.login(process.env.token);