Files
BotsCord/website/bot/index.js
T
2022-08-13 08:26:49 +02:00

120 lines
4.7 KiB
JavaScript

const client = require('../../index.js').client;
const servers = require('../../models/server');
const bots = require('../../models/bot');
const users = require('../../models/user');
var config = client.config
const { SlashCommandBuilder, Routes, EmbedBuilder } = require('discord.js');
const { REST } = require('@discordjs/rest');
const colors = require('colors');
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
new SlashCommandBuilder().setName('topvoted').setDescription('Replies with highest server/bots!'),
new SlashCommandBuilder().setName('user').setDescription('Replies with user info and connected bots/servers!'),
new SlashCommandBuilder().setName('queue').setDescription('Replies with queue'),
]
.map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(config.bot.token);
rest.put(Routes.applicationGuildCommands(config.bot.id, config.discord.id), { body: commands })
.then(() => console.log(colors.green("Website: "), 'Successfully registered application commands.'))
.catch(console.error);
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
await interaction.reply('Pong!');
} else if (commandName === 'topvoted') {
const serversdata = await servers.find();
const botsdata = await bots.find({ verified: true });
var botsdata1 = botsdata
.sort((a, b) => b.votes - a.votes)
.slice(0, 6)
.map(
a => `${a.name} **[ \`${a.votes}\` Votes ]**`
)
.join('\n');
var serversdata1 = serversdata
.sort((a, b) => b.votes - a.votes)
.slice(0, 6)
.map(
a => `${a.name} | ${a.id} **[ \`${a.votes}\` Votes ]**`
)
.join('\n');
if (!serversdata1) {
var serversdata1 = 'no servers';
}
if (!botsdata1) {
var botsdata1 = 'no bots';
}
const embed = new EmbedBuilder()
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.avatarURL({ dynamic: true }) })
.setColor("#7289da")
.setDescription(`**Top 6 voted bots of the week!**\n${botsdata1}\n\n**Top 6 voted servers of the week!**\n${serversdata1}`)
interaction.reply({ embeds: [embed] });
} else if (commandName === 'user') {
const { user } = interaction;
await interaction.reply(`${user.username}#${user.discriminator} has ${user.bot ? 'a bot' : 'no bot'} and is connected to ${user.guilds.size} servers!`);
} else if (commandName === 'queue') {
if (!global.config.users.owner.includes(interaction.user.id) && !global.config.users.verificator.includes(interaction.user.id)) return interaction.reply('You are not allowed to use this command!');
const unVerified = await bots.find({ verified: false });
var desc = "";
for (let i = 0; i < unVerified.length; i++) {
desc += `${i + 1}. ${unVerified[i].name} - ${unVerified[i].id} Invite: https://discord.com/api/oauth2/authorize?client_id=${unVerified[i].id}&scope=applications.commands%20bot\n`;
}
const embed = new EmbedBuilder()
.setTitle('Unverified Bots')
.setDescription(desc)
.setColor("#5865F2")
.setFooter({ text: 'BotsCord', iconURL: 'https://botscord.xyz/img/logo.png' })
.setTimestamp()
interaction.reply({ embeds: [embed] });
}
});
client.on("guildMemberAdd", async (member) => {
let guild = client.guilds.cache.get(config.discord.id);
if (member.user.bot) {
try {
guild.member(member.id).roles.add(config.server.roles.botlist.bot);
} catch (error) {
}
} else {
try {
guild.member(member.id).roles.add(config.server.roles.botlist.user);
} catch (error) {
}
}
});
var cooldown = [];
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
// cooldown function
if (cooldown.includes(message.author.id)) return;
cooldown.push(message.author.id);
const coins = await users.findOne({ id: message.author.id });
if (!coins) {
await users.create({ id: message.author.id, coins: 0 });
} else {
if (coins.coins < 1) {
coins.coins = 1;
coins.save();
} else {
coins.coins++;
coins.save();
}
message.reply(`You have ${coins.coins} coins!`);
setTimeout(() => {
cooldown.splice(cooldown.indexOf(message.author.id), 1);
}, 1200000);
}
});