WIP http for gractwo.pl

This commit is contained in:
2021-05-06 18:29:20 +02:00
parent 24b78a396c
commit 07d5ff9a0f

144
index.js
View File

@@ -5,96 +5,164 @@ const fs = require('fs');
const client = new Discord.Client(); const client = new Discord.Client();
client.commands = new Discord.Collection(); client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const commandFiles = fs
.readdirSync('./commands')
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) { for (const file of commandFiles) {
const command = require(`./commands/${file}`); const command = require(`./commands/${file}`);
client.commands.set(command.name, command); client.commands.set(command.name, command);
} }
client.once('ready', () =>{ client.once('ready', () => {
console.log('-------------------------------------\nTHE BOT IS READY TO GO.\n-------------------------------------'); console.log(
}) '-------------------------------------\nTHE BOT IS READY TO GO.\n-------------------------------------'
);
client.on('message', message => { });
client.on('message', (message) => {
/* OMITTING THE COMMAND HANDLER TO CATCH ANY AND ALL MESSAGES IN THE '#rolki' CHANNEL /* OMITTING THE COMMAND HANDLER TO CATCH ANY AND ALL MESSAGES IN THE '#rolki' CHANNEL
MAKING 'tf2' A VIABLE COMMAND WITHOUT A PREFIX */ MAKING 'tf2' A VIABLE COMMAND WITHOUT A PREFIX */
// command handler is downward from this if statement // command handler is downward from this if statement
if(message.channel.name == 'rolki'){ if (message.channel.name == 'rolki') {
if (message.author.bot) return;
if(message.author.bot) return; if (
message.content == 'tf2' ||
if(message.content == 'tf2' || message.content == 'liga' || message.content == 'csgo' || message.content == 'minecraft' || message.content == 'rainbow-six'){ message.content == 'liga' ||
const role = message.member.guild.roles.cache.find(role => role.name == message.content) message.content == 'csgo' ||
if(message.member.roles.cache.find(role => role.name == message.content)){ message.content == 'minecraft' ||
message.content == 'rainbow-six'
) {
const role = message.member.guild.roles.cache.find(
(role) => role.name == message.content
);
if (
message.member.roles.cache.find((role) => role.name == message.content)
) {
message.member.roles.remove(role); message.member.roles.remove(role);
message.delete(); message.delete();
console.log(`removed ${message.author.username}'s ${message.content} role.`); console.log(
`removed ${message.author.username}'s ${message.content} role.`
);
const removeRolesEmbed = new Discord.MessageEmbed() const removeRolesEmbed = new Discord.MessageEmbed()
.setTitle(`Odebrano Ci rangę ${message.content}, ${message.author.username}.`) .setTitle(
`Odebrano Ci rangę ${message.content}, ${message.author.username}.`
)
.setColor(config.embedColor) .setColor(config.embedColor)
.attachFiles('./gractwo.png') .attachFiles('./gractwo.png')
.setFooter('#rolki','attachment://gractwo.png') .setFooter('#rolki', 'attachment://gractwo.png')
.setTimestamp(); .setTimestamp();
message.channel.send(removeRolesEmbed) message.channel
.then(message => message.delete({timeout: 3500})) .send(removeRolesEmbed)
.then((message) => message.delete({ timeout: 3500 }))
.catch(console.error); .catch(console.error);
}else{ } else {
message.member.roles.add(role); message.member.roles.add(role);
message.delete(); message.delete();
console.log(`added ${message.content} role to ${message.author.username}.`); console.log(
`added ${message.content} role to ${message.author.username}.`
);
const addRolesEmbed = new Discord.MessageEmbed() const addRolesEmbed = new Discord.MessageEmbed()
.setTitle(`Przyznano Ci rangę ${message.content}, ${message.author.username}.`) .setTitle(
`Przyznano Ci rangę ${message.content}, ${message.author.username}.`
)
.setColor(config.embedColor) .setColor(config.embedColor)
.attachFiles('./gractwo.png') .attachFiles('./gractwo.png')
.setFooter('#rolki','attachment://gractwo.png') .setFooter('#rolki', 'attachment://gractwo.png')
.setTimestamp(); .setTimestamp();
message.channel.send(addRolesEmbed) message.channel
.then(message => message.delete({timeout: 3500})) .send(addRolesEmbed)
.then((message) => message.delete({ timeout: 3500 }))
.catch(console.error); .catch(console.error);
} }
}else{ } else {
if(!message.member.roles.cache.find(role => role.name == 'Moderatorzy')){ if (
console.log(`${message.author.username} spammed the rolki channel with a bad message`); !message.member.roles.cache.find((role) => role.name == 'Moderatorzy')
) {
console.log(
`${message.author.username} spammed the rolki channel with a bad message`
);
message.delete(); message.delete();
const rolkiWrongMessageEmbed = new Discord.MessageEmbed() const rolkiWrongMessageEmbed = new Discord.MessageEmbed()
.setTitle(`To nie jest kanał na pisanie, ${message.author.username}`) .setTitle(`To nie jest kanał na pisanie, ${message.author.username}`)
.setColor(config.embedColorFail) .setColor(config.embedColorFail)
.attachFiles('./gractwo.png') .attachFiles('./gractwo.png')
.setFooter('#rolki','attachment://gractwo.png') .setFooter('#rolki', 'attachment://gractwo.png')
.setTimestamp(); .setTimestamp();
message.channel.send(rolkiWrongMessageEmbed) message.channel
.then(message => message.delete({timeout: 3500})) .send(rolkiWrongMessageEmbed)
.then((message) => message.delete({ timeout: 3500 }))
.catch(console.error); .catch(console.error);
return; return;
} }
} }
} }
if (!message.content.startsWith(config.prefix) || message.author.bot) return; if (!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/); const args = message.content.slice(config.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase(); const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return; if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName); const command = client.commands.get(commandName);
if (command.guildOnly && message.channel.type === 'dm') { if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!'); return message.reply("I can't execute that command inside DMs!");
} }
if (command.args && !args.length) { if (command.args && !args.length) {
return message.channel.send(`You didn't provide any arguments, ${message.author}!`); return message.channel.send(
`You didn't provide any arguments, ${message.author}!`
);
} }
try{ try {
command.execute(message, args, Discord, config, client); command.execute(message, args, Discord, config, client);
}catch(error){ } catch (error) {
console.error(error); console.error(error);
message.reply('there was an error trying to execute that command.'); message.reply('there was an error trying to execute that command.');
} }
}); });
client.login(process.env.BOT_TOKEN); client.login(process.env.BOT_TOKEN);
// Funne API hehehehe
const http = require('http');
const port = process.env.PORT || 3000;
http
.createServer(async (req, res) => {
res.statusCode = 200;
let totalSeconds = process.uptime();
let realTotalSecs = Math.floor(totalSeconds % 60);
let days = Math.floor((totalSeconds % 31536000) / 86400);
let hours = Math.floor((totalSeconds / 3600) % 24);
let mins = Math.floor((totalSeconds / 60) % 60);
let used = process.memoryUsage().heapUsed / 1024 / 1024;
res.write(
JSON.stringify({
username: client.user.username,
avatar: client.user.avatarURL(),
status: client.user.presence.status,
activity: `${
client.user.presence.activities[0].type[0].toUpperCase() +
client.user.presence.activities[0].type.toLowerCase().slice(1)
} ${client.user.presence.activities[0].name}`,
members: client.users.cache.size,
uptime: {
days,
hours,
mins,
realTotalSecs,
},
memory: `${Math.round(used * 100) / 100}MB`,
ping: `${Math.floor(client.ws.ping)}ms`,
node: process.version,
})
);
res.end();
})
.listen(port, () => console.log(`Now listening on port ${port}`));