-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
148 lines (143 loc) · 6.93 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const Discord = require('discord.js')
const client = new Discord.Client({
intents: 32767
})
const tw = require('@fortune-inc/tw-voucher')
const config = require('./config.json')
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const fs = require('fs');
const chalk = require('chalk')
var chalkRainbow = require('chalk-rainbow')
let commands = [];
fs.readdir('commands', (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
try {
let props = require(`./commands/${f}`);
commands.push({
name: props.name,
description: props.description,
options: props.options
});
} catch (err) {
console.log(err);
}
});
});
client.on('interactionCreate', async (interaction) => {
if (interaction.type != 2) return;
fs.readdir('commands', (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
let props = require(`./commands/${f}`);
if (interaction.commandName.toLowerCase() === props.name.toLowerCase()) {
try {
if ((props?.permissions?.length || [].length) > 0) {
(props?.permissions || [])?.map(perm => {
if (interaction.member.permissions.has(config.permissions[perm])) {
return props.run(client, interaction);
} else {
return interaction.reply({ content: `Missing permission: **${perm}**`, ephemeral: true });
}
})
} else {
return props.run(client, interaction);
}
} catch (e) {
return interaction.reply({ content: `Something went wrong...\n\n\`\`\`${e.message}\`\`\``, ephemeral: true });
}
}
});
});
});
const rest = new REST({ version: "9" }).setToken(config.token);
client.once("ready", () => {
(async () => {
try {
await rest.put(Routes.applicationCommands(client.user.id), {
body: await commands,
});
console.log(chalkRainbow(`Login : ${client.user.tag}`))
} catch { };
})();
});
client.login(config.token)
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
if (interaction.customId == "ซื้อยศ") {
const modal = new Discord.ModalBuilder()
.setCustomId('topup')
.setTitle('ซองอังเปา(ไม่มีการคืนเงิน)');
const codeInput = new Discord.TextInputBuilder()
.setCustomId('codeInput')
.setLabel("ลิ้งค์ซองอังเปา")
.setPlaceholder('https://gift.truemoney.com/campaign/?v=xxxxxxxxxxxxxxx')
.setStyle(Discord.TextInputStyle.Short);
const codeInputActionRow = new Discord.ActionRowBuilder().addComponents(codeInput);
modal.addComponents(codeInputActionRow);
await interaction.showModal(modal);
}
}
if (interaction.isButton()) {
if (interaction.customId == "ช่วยเหลือ") {
await interaction.reply({
embeds: [new Discord.EmbedBuilder()
.setColor("Green")
.setTitle("ราคายศ")
.setDescription(`เติมเงิน 40 บาท จะได้ยศ\n-> <@&${config.role40}>`)], ephemeral: true
})
}
}
if (interaction.type === 5) {
if (interaction.customId === "topup") {
const codeInput = interaction.fields.getTextInputValue('codeInput')
console.log(`URL:${codeInput} DISCORD-ID:${interaction.user.id}`)
if (!codeInput.includes("https://gift.truemoney.com/campaign/?v")) return await interaction.reply({
embeds: [
new Discord.EmbedBuilder()
.setColor("Red")
.setDescription('เติมเงินไม่สำเร็จ : ลิ้งค์รับเงินแล้ว/ลิ้งค์ผิด')
], ephemeral: true
})
tw(config.phone, codeInput).then(async re => {
switch (re.amount) {
case 40:
if (interaction.member.roles.cache.has(config.role40)) {
await interaction.reply({ embeds: [new Discord.EmbedBuilder().setColor("Green").setDescription("เติมเงินสำเร็จ : คุณมียศอยู่แล้ว")], ephemeral: true })
await interaction.guild.channels.cache.get(config.channellog).send({
embeds: [
new Discord.EmbedBuilder()
.setDescription(`เติมเงินสำเร็จ ${re.amount} โดย <@${interaction.user.id}>`)
.addFields({
name: `คุณได้รับยศ`,
value: `• <@&${config.role40}>`
})
.setColor("Green")
]
})
} else {
await interaction.member.roles.add(config.role40)
await interaction.reply({ embeds: [new Discord.EmbedBuilder().setColor("Green").setDescription("เติมเงินสำเร็จ")], ephemeral: true })
await interaction.guild.channels.cache.get(config.channellog).send({
embeds: [
new Discord.EmbedBuilder()
.setDescription(`เติมเงินสำเร็จ ${re.amount} โดย <@${interaction.user.id}>`)
.addFields({
name: `คุณได้รับยศ`,
value: `• <@&${config.role40}>`
})
.setColor("Green")
]
})
}
break;
default:
break;
}
}).catch(async e => {
await interaction.reply({ embeds: [new Discord.EmbedBuilder().setColor("Red").setDescription("ลิงค์ผิดหรืออาจมีคนใช้ไปแล้ว")], ephemeral: true })
})
}
};
})