-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce9e52
commit 7fc8226
Showing
4 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const PixelListener = require('../../structures/PixelListener'); | ||
const fetch = require("node-fetch"); | ||
const { EmbedBuilder, codeBlock } = require('discord.js'); | ||
const { ObjectId } = require('mongodb'); | ||
|
||
class InteractionCreateListener extends PixelListener { | ||
constructor() { | ||
super('InteractionCreateListener', { event: 'interactionCreate' }); | ||
} | ||
|
||
async run(client, interaction) { | ||
if(!interaction.isButton()) return; | ||
if(!interaction.customId.startsWith('ban_acc_')) return; | ||
if(!client.permissions.moderator.has(interaction.user.id)) | ||
return interaction.reply({ | ||
content: 'У вас слишком низкий уровень прав для совершения данного действия!', | ||
ephemeral: true | ||
}); | ||
if(interaction.message.embeds[0].fields.length > 1) | ||
return interaction.reply({ | ||
content: 'С данным игроком уже совершено действие, вы не можете совершить его снова', | ||
ephemeral: true | ||
}); | ||
|
||
await interaction.deferReply({ ephemeral: true }); | ||
|
||
const _id = new ObjectId(interaction.customId.slice(8)); | ||
const user = await client.database.collection('users').findOne({ _id }); | ||
|
||
if(!user) | ||
return interaction.editReply('Игрок отсутствует в базе данных PixelBattle').catch(() => {}); | ||
if(user.banned) | ||
return interaction.editReply('Игрок уже забанен').catch(() => {}); | ||
|
||
const ban_data = { | ||
timeout: Date.now() + 172800000000, | ||
reason: '[AUTO] Аккаунт подозрителен, поскольку зарегестрирован недавно' | ||
}; | ||
|
||
const response = await fetch(`${client.config.api_domain}/users/${user.userID}/ban`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Bearer ' + (await client.database.collection('users').findOne( | ||
{ userID: interaction.user.id }, | ||
{ projection: { _id: 0, token: 1 } } | ||
))?.token | ||
}, | ||
body: JSON.stringify(ban_data) | ||
}).then(res => res?.json()); | ||
if(response?.error ?? !response) | ||
return interaction.editReply('Попытка бана прошла неудачно\n' + response ? codeBlock('json', JSON.stringify(response)) : ''); | ||
|
||
await client.database.collection('users').updateOne( | ||
{ _id }, | ||
{ | ||
$set: { | ||
banned: { | ||
moderatorID: interaction.user.id, | ||
...ban_data | ||
} | ||
} | ||
} | ||
); | ||
|
||
interaction.message.edit({ | ||
embeds: [ | ||
new EmbedBuilder(interaction.message.embeds[0]) | ||
.setTimestamp() | ||
.setFooter({ text: interaction.user.username, iconURL: interaction.user.avatarURL() }) | ||
.addFields([ | ||
{ | ||
name: '🛠️ Предпринятые действия', | ||
value: | ||
`> Игрок был заблокирован (MOD: \`${interaction.user.id}\`)` | ||
} | ||
]) | ||
] | ||
}).catch(() => {}); | ||
|
||
return interaction.editReply('Игрок был успешно заблокирован! Вы можете закрыть это сообщение.') | ||
.catch(() => {}); | ||
} | ||
} | ||
|
||
module.exports = InteractionCreateListener; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const PixelListener = require('../../structures/PixelListener'); | ||
const AntiNewAccountService = require('../../services/AntiNewAccountService'); | ||
|
||
class MemberAddListener extends PixelListener { | ||
constructor() { | ||
super('MemberAddListener', { event: 'guildMemberAdd' }); | ||
} | ||
|
||
run(client, member) { | ||
if(member.user.createdTimestamp >= (Date.now() - client.config.maximumNewAccountDetectionTime)) new AntiNewAccountService(client).sendNotification(member); | ||
} | ||
} | ||
|
||
module.exports = MemberAddListener; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); | ||
|
||
class AntiNewAccountService { | ||
constructor(client) { | ||
this.client = client; | ||
this.channel = client.channels.cache.get(client.config.notificationChannel) | ||
} | ||
|
||
async sendNotification(member) { | ||
return this.channel.send({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setTitle('Оповещение о новом аккаунте') | ||
.setFooter({ text: 'Здесь появится ник модератора, предпринявшего действие' }) | ||
.setThumbnail(member.user.avatarURL()) | ||
.setFields([ | ||
{ | ||
name: '🍎 Информация', | ||
value: | ||
`> ID: \`${member.id}\`\n` + | ||
`> Тег: \`${member.user.tag}\`\n` + | ||
`> Ник: \`${member.nickname || 'отсутсвует'}\`\n` + | ||
`> Дата регистрации: <t:${Math.ceil(member.user.createdTimestamp / 1000)}>\n` | ||
} | ||
]) | ||
.setColor(0x5865F2) | ||
], | ||
components: [ | ||
new ActionRowBuilder() | ||
.addComponents([ | ||
new ButtonBuilder() | ||
.setLabel('Забанить') | ||
.setStyle(ButtonStyle.Danger) | ||
.setEmoji('⚠️') | ||
.setCustomId(`ban_acc_${(await this.client.database.collection('users').findOne({ userID: member.id }))._id}`) | ||
]) | ||
] | ||
}); | ||
} | ||
} | ||
|
||
module.exports = AntiNewAccountService; |