This repository has been archived by the owner on Jul 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
396 lines (394 loc) · 13.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
const { Client, Intents, MessageActionRow, MessageSelectMenu, MessageButton, MessageAttachment, Permissions } = require('discord.js');
const { Modal, TextInputComponent, showModal } = require('discord-modals');
const Canvas = require('canvas');
const discordModals = require('discord-modals');
const fs = require("node:fs");
const slashs = require("./slash.json");
const config = require("./config.json");
const BitlyClient = require('bitly').BitlyClient;
const bitly = new BitlyClient(config.bitly);
const write = data => {
const datas = require("./data.json");
const guildId = data.gd;
const tmp = new Object();
if (!datas.some(() => guildId)) {
tmp[guildId] = data.options;
datas.push(tmp)
this.writedata = datas
} else {
let i = 0;
datas.splice([datas.map(x => {
if (x[guildId]) return i
i++
})[0]]);
tmp[guildId] = data.options;
datas.push(tmp)
this.writedata = datas
};
fs.writeFileSync('./data.json', JSON.stringify(this.writedata, null, 2), 'utf8')
};
const code_type = { "number": "数字", "number_alp": "英数字", "alp": "英字" }
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS]
});
discordModals(client);
/* 各宣言 */
const image_button_back_modal = new Modal()
.setCustomId('modal_image_back')
.setTitle('画像URLを入力してください')
.addComponents(
new TextInputComponent()
.setCustomId('textinput_image_back')
.setLabel('注:画像URLは短縮URLに自動で変換されます\nご了承ください')
.setStyle('SHORT')
.setPlaceholder('ここに入力')
.setRequired(true)
);
const image_button_message_modal = new Modal()
.setCustomId('modal_image_message')
.setTitle('生成メッセージを入力(1000字以内)')
.addComponents(
new TextInputComponent()
.setCustomId('textinput_image_message')
.setLabel('認証ユーザーのDMに送るメッセージです')
.setStyle('LONG')
.setMaxLength(1000)
.setPlaceholder('ここに入力')
.setRequired(true)
);
const image_button_start_modal = new Modal()
.setCustomId('modal_image_start')
.setTitle('生成メッセージを入力(2000字以内)')
.addComponents(
new TextInputComponent()
.setCustomId('textinput_image_start')
.setLabel('ボタンを作成する際のメッセージです')
.setStyle('LONG')
.setMaxLength(2000)
.setPlaceholder('ここに入力')
.setRequired(true)
);
const image_button = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('image_button_back')
.setLabel('背景画像変更')
.setStyle('PRIMARY'),
new MessageButton()
.setCustomId('image_button_message')
.setLabel('認証後のメッセージ変更')
.setStyle('PRIMARY'),
new MessageButton()
.setCustomId('image_button_start')
.setLabel('作成')
.setStyle('PRIMARY')
);
const image_select = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select_code_type')
.setPlaceholder('数字')
.addOptions([
{
label: '数字',
description: '生成コードを数字にします',
value: 'number',
},
{
label: '英数字',
description: '生成コードを英数字にします',
value: 'number_alp',
},
{
label: '英字',
description: '生成コードを英字にします',
value: 'alp',
},
]),
);
const image_start = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('image_button_auth')
.setLabel('認証')
.setStyle('PRIMARY'),
);
/* イベント開始 */
client.on('ready', async () => {
client.user.setActivity(`導入数 ${client.guilds.cache.size} `, {
type: 'PLAYING',
});
await client.application.commands.set(slashs, config.slashserver);
console.log("処理が完了しました")
});
client.on("interactionCreate", async interaction => {
/* サーバー以外でのコマンドは無視 */
if (!interaction.guild) return interaction.reply({
embeds: [{
title: "エラー",
description: "DMではできないです",
color: 0xff1100
}],
});
/* メッセージ送信権限がなかったら処理中断 */
if (!interaction.guild.me.permissionsIn(interaction.channel).has("2048")) return;
/* メイン */
if (interaction.isCommand()) {
if (interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "あなたには管理者権限がありません。"
}],
ephemeral: true
});
const role = interaction.options.getRole("role").id;
const type = interaction.options.getString("option");
if (!interaction.guild.me.permissionsIn(interaction.channel).has("268435456")) return interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "ロールをつける権限がありません。"
}],
ephemeral: true
});
/* web認証 */
if (type == "web") {
interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "まだ実装されていません"
}],
ephemeral: true
});
};
/* 画像認証 */
if (type == "image") {
interaction.guild.me.roles.add(role)
.catch(() => {
interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "ロール権限がBOTよりも上です"
}],
ephemeral: true
})
})
//画像操作画面
.then(data => {
if (!data) return;
interaction.guild.me.roles.remove(role).catch(() => { })
write({ gd: interaction.guildId, options: { btms: null, btbk: null, ath: "number", role: role } });
interaction.reply({
embeds: [{
color: 0x00ff22,
title: "画像認証コントロール画面",
description: `背景:デフォルト\n生成コード:数字\n認証後のメッセージ:なし`
}],
components: [image_button, image_select],
ephemeral: true
});
});
};
/* パスワード認証 */
if (type == "password") {
interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "まだ実装されていません"
}],
ephemeral: true
});
};
/* インプットテキスト認証 */
if (type == "input") {
interaction.reply({
embeds: [{
title: "エラー",
color: 0xff1100,
description: "まだ実装されていません"
}],
ephemeral: true
});
}
};
/* ボタン */
if (interaction.isButton()) {
if (interaction.customId == "image_button_back") {
showModal(image_button_back_modal, {
client: client,
interaction: interaction
});
};
if (interaction.customId == "image_button_message") {
showModal(image_button_message_modal, {
client: client,
interaction: interaction
});
};
if (interaction.customId == "image_button_start") {
showModal(image_button_start_modal, {
client: client,
interaction: interaction
});
};
if (interaction.customId == "image_button_auth") {
await interaction.deferReply({ ephemeral: true })
let tmp;
const datas = require("./data.json");
const data = datas.filter(x => Object.keys(x)[0] == interaction.guildId)[0][interaction.guildId];
if (data.ath == "number") tmp = "123456789"
if (data.ath == "number_alp") tmp = "abcdefghjkmnpqrstuvwxyzABCDEFZHIJKLMNOPQRSTUVWXYZ1234567890"
if (data.ath == "alp") tmp = "abcdefghjkmnpqrstuvwxyzABCDEFZHIJKLMNOPQRSTUVWXYZ"
const password = Array.from(Array(6)).map(() => tmp[Math.floor(Math.random() * tmp.length)]).join('');
const canvas = Canvas.createCanvas(700, 250);
const context = canvas.getContext('2d');
let background = await Canvas.loadImage(data.btbk || "https://beiz.jp/images_S/black/black_00070.jpg").catch(() => { });
if (!background) background = await Canvas.loadImage("https://beiz.jp/images_S/black/black_00070.jpg");
context.drawImage(background, 0, 0, canvas.width, canvas.height);
context.strokeRect(0, 0, canvas.width, canvas.height);
context.font = '60px sans-serif';
context.fillStyle = '#ffffff';
context.fillText(password, canvas.width / 2.5, canvas.height / 1.8);
const attachment = new MessageAttachment(canvas.toBuffer(), 'auth.png');
const image_auth = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId(`image_button_auth_user,${password}`)
.setLabel('認証')
.setStyle('PRIMARY'),
);
interaction.followUp({ files: [attachment], components: [image_auth], ephemeral: true });
};
if (interaction.customId.startsWith("image_button_auth_user")) {
const password = interaction.customId.split(",")[1]
const image_button_auth_modal = new Modal()
.setCustomId(`modal_image_check,${password}`)
.setTitle('パスワードを入力')
.addComponents(
new TextInputComponent()
.setCustomId(`image_check`)
.setLabel('パスワードを入力してください')
.setStyle('SHORT')
.setMinLength(6)
.setMaxLength(6)
.setPlaceholder('ここに入力')
.setRequired(true)
);
showModal(image_button_auth_modal, {
client: client,
interaction: interaction
});
};
};
/* セレクトメニュー */
if (interaction.isSelectMenu()) {
if (interaction.customId == "select_code_type") {
const type = interaction.values[0];
await interaction.deferReply({ ephemeral: true });
const datas = require("./data.json");
const data = datas.filter(x => Object.keys(x)[0] == interaction.guildId)[0][interaction.guildId];
write({ gd: interaction.guildId, options: { btms: data.btms || null, btbk: data.btbk, ath: type, role: data.role } });
interaction.followUp({
embeds: [{
color: 0x00ff22,
title: "画像認証コントロール画面",
description: `背景:${data.btms || "デフォルト"}\n生成コード:${code_type[type]}\n認証後のメッセージ:${data.btms || "なし"}`
}],
components: [image_button, image_select],
ephemeral: true
});
};
};
});
client.on("modalSubmit", async modal => {
await modal.deferReply({ ephemeral: true });
const datas = require("./data.json");
const data = datas.filter(x => Object.keys(x)[0] == modal.guildId)[0][modal.guildId];
if (modal.customId === 'modal_image_back') {
const url = modal.getTextInputValue('textinput_image_back');
const response = await bitly.shorten(url).catch(() => { });
if (!response) return modal.followUp({
embeds: [{
color: 0xff1100,
title: "エラー",
description: "URLではありません"
}],
ephemeral: true
});
write({ gd: modal.guildId, options: { btms: data.btms || null, btbk: response.link, ath: data.ath, role: data.role } });
modal.followUp({
embeds: [{
color: 0x00ff22,
title: "画像認証コントロール画面",
description: `背景:${response.link || "デフォルト"}\n生成コード:${code_type[data.ath]}\n認証後のメッセージ:${data.btms || "なし"}`
}],
components: [image_button, image_select],
ephemeral: true
});
};
if (modal.customId === 'modal_image_message') {
const message = modal.getTextInputValue('textinput_image_message');
write({ gd: modal.guildId, options: { btms: message || null, btbk: data.btbk || null, ath: data.ath, role: data.role } });
modal.followUp({
embeds: [{
color: 0x00ff22,
title: "画像認証コントロール画面",
description: `背景:${data.btbk || "デフォルト"}\n生成コード:${code_type[data.ath]}\n認証後のメッセージ:${message || "なし"}`
}],
components: [image_button, image_select],
ephemeral: true
});
};
if (modal.customId == "modal_image_start") {
modal.followUp({
embeds: [{ title: "作成に成功しました", color: 0x00ff22 }]
});
modal.channel.send({
embeds: [{
title: "認証",
description: modal.getTextInputValue('textinput_image_start'),
color: 0x00ff22
}],
components: [image_start]
});
};
if (modal.customId.startsWith("modal_image_check")) {
const input = modal.getTextInputValue('image_check');
const check = modal.customId.split(",")[1];
if (input == check) {
modal.member.roles.add(data.role)
.catch(() => {
modal.followUp({
embeds: [{
color: 0xff1100,
title: "エラー",
description: "BOTの権限が足りないです"
}]
});
})
.then(data => {
if (!data) return;
modal.followUp({
embeds: [{
color: 0x00ff22,
title: "成功",
description: data.btms || "認証に成功しました"
}]
});
});
} else {
modal.followUp({
embes: [{
color: 0xff1100,
title: "間違っています",
ephemeral: true
}]
});
};
};
});
client.login(config.token)