Skip to content

Commit

Permalink
Rebuild discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Furman1331 committed May 30, 2021
1 parent a8fd876 commit 3cbd663
Show file tree
Hide file tree
Showing 35 changed files with 491 additions and 1,075 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
20 changes: 20 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { prefix } = require('./settings.json');

module.exports = (client, aliases, callback) => {
if (typeof aliases === 'string') {
aliases = [aliases]
}

client.on('message', message => {
const { content } = message;

aliases.forEach(alias => {
const command = `${prefix}${alias}`

if (content.startsWith(`${command}`) || content === command) {
console.log(`Running the command ${command}`);
callback(message)
}
})
})
}
48 changes: 46 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
const { strict } = require('assert');
const Discord = require('discord.js');
const fs = require('fs');
const { stringify } = require('querystring');
const client = new Discord.Client();
const settings = require('./settings.json');
const prefix = settings.prefix || "!";

const command = require('./command');
const memberCount = require('./modules/countMember')

client.info = require("./warn.json");

client.on('ready', async () => {
console.log(`Pomyślnie uruchomiono bota ${settings.name}!`);
await client.user.setActivity('!help © FurmanBot', {type: "WATCHING"}).then(presence => console.log(`Pomyślnie ustawiono aktywność dla bota ${settings.name}!`)).catch(console.error);
memberCount(client);
await client.user.setActivity('!help © CentrumRP Bot - Niedługo Start', {type: "WATCHING"}).then(presence => console.log(`Pomyślnie ustawiono aktywność dla bota ${settings.name}!`)).catch(console.error);
});

client.on('message', async message => {
Expand All @@ -27,7 +33,7 @@ client.on('message', async message => {
message.author.send(`Dostępne komedy: \`\`\`!help - Dostępne komendy\n!faq - Najczęściej zadawane pytania.\`\`\``).then(message => setTimeout(() => {message.delete();}, settings.timeToDelete));
}
else if (command === 'faq'){
message.author.send(`Dlaczego serwer jest OFF ? - OVH miało awarie i obecnie czekamy na nowy serwer.`).then(messages => setTimeout(() => {message.delete();}, settings.timeToDelete));
message.author.send(`Dlaczego serwer jest OFF ? - Obecnie trwają prace techniczne.`).then(messages => setTimeout(() => {message.delete();}, settings.timeToDelete));
}
else if(command === 'clear') {
if(message.member.hasPermission("MANAGE_MESSAGES")) {
Expand Down Expand Up @@ -87,6 +93,44 @@ client.on('message', async message => {
.then(messages => ClearMessagesAfterTime([message, messages], settings.timeToDelete));
}
}
else if (command === 'wl-losuj') {
if(message.member.hasPermission("ADMINISTRATOR") || (message.guild.roles.cache.find(role => role.name === "Whitelist Checker"))) {
const whitelistCheckerChannel = message.member.voice.channel
client.channels.fetch(settings.waitingRoom).then(channel => {
const randomUser = channel.members.random();
if (!randomUser) return message.channel.send(`Obecnie nie ma osób w kolejce, ${message.author}.`).then(messages =>ClearMessagesAfterTime([message, messages], settings.timeToDelete));
return message.channel.send(`Do zdania Whitelisty wylosowano, ${randomUser}`).then(randomUser.voice.setChannel(whitelistCheckerChannel));
})
}
}
else if (command === 'wl-zdal') {
if(message.member.hasPermission("ADMINISTRATOR") || (message.guild.roles.cache.find(role => role.name === "Whitelist Checker"))) {
const user = message.mentions.users.first();
if(!user) return message.channel.send(`Nie ma takiego użytkownika, ${message.author}!`).then(messages => ClearMessagesAfterTime([message, messages], settings.timeToDelete));

let filter = m => m.author.id === message.author.id
message.channel.send(`Czy napewno nadać white liste dla ${user.username}, \'tak\' / \'nie\'`).then(() => {
message.channel.awaitMessages(filter, {
max: 1,
time: 30000,
errors: ['time']
}).then(message => {
message = message.first()
if (message.content.toUpperCase() == 'TAK' || message.content.toUpperCase() == 'YES') {
const target = message.guild.members.cache.get(user.id)
target.roles.add(settings.whitelistRole)
return message.channel.send(`Nadano whiteliste dla obywatela, ${message.author}.`).then(messages => ClearMessagesAfterTime([message, messages], settings.timeToDelete));
} else if (message.content.toUpperCase() == 'NIE' || message.content.toUpperCase() == 'NO') {
return message.channel.send(`Zrezygnowano, ${message.author}.`).then(messages => ClearMessagesAfterTime([message, messages], settings.timeToDelete));
} else {
return message.channel.send(`Błąd podczas wpisywania, ${message.author}.`).then(messages => ClearMessagesAfterTime([message, messages], settings.timeToDelete));
}
}).catch(collected => {
message.channel.send(`ERROR: ${collected}`);
});
})
}
}
});

function getUserFromMark(user) {
Expand Down
24 changes: 24 additions & 0 deletions modules/countMember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const axios = require('axios')
const options = require('../options').options;
module.exports = async(client) => {
client.setInterval(async () => {
count servers = [];
let total = 0;
for(const server of options.servers) {
let players = await getPlayers(`${server.url}/players.json`);
servers.push({
name: server.name,
count: players.data.lenght,
})
total =+ players.data.lenght,
};
}, options.pollRate * 1000);
}

const getPlayers = async server => {
try {
return axios.get(`${server}/players.json`, { responseType:'json', timeout: 10000 })
} catch(e){
console.log(e);
}
};
50 changes: 25 additions & 25 deletions node_modules/discord.js/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/discord.js/src/client/actions/InviteDelete.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions node_modules/discord.js/src/client/voice/ClientVoiceManager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 0 additions & 40 deletions node_modules/discord.js/typings/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions node_modules/discord.js/webpack/discord.js

This file was deleted.

Loading

0 comments on commit 3cbd663

Please sign in to comment.