Skip to content

Commit

Permalink
added twink detection system
Browse files Browse the repository at this point in the history
  • Loading branch information
mirdukkkkk committed Feb 8, 2024
1 parent 0ce9e52 commit 7fc8226
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PixelClient = require('./structures/PixelClient');
const client = new PixelClient({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildBans,
IntentsBitField.Flags.GuildModeration,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildInvites,
IntentsBitField.Flags.GuildMessages,
Expand Down
86 changes: 86 additions & 0 deletions src/listeners/interactions/InteractionCreateListener.js
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;
14 changes: 14 additions & 0 deletions src/listeners/members/MemberAddListener.js
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;
42 changes: 42 additions & 0 deletions src/services/AntiNewAccountService.js
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;

0 comments on commit 7fc8226

Please sign in to comment.