Added the 'Selmer Specific' file, added the 'welcome' and 'setup' commands

This commit is contained in:
ION606
2022-06-10 16:19:47 +03:00
parent 789ca684ca
commit b441f6b773
12 changed files with 512 additions and 41 deletions
+108 -39
View File
@@ -1,8 +1,9 @@
const { Client, Intents, Permissions } = require('discord.js');
const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu } = require('discord.js');
const Discord = require('discord.js');
const { MongoClient, ServerApiVersion } = require('mongodb');
const fs = require('fs');
const turnManager = require('./commands/turnManager.js');
const { welcome } = require('./commands/admin/welcome.js');
const { exit } = require('process');
const BASE_LVL_XP = 20;
@@ -29,7 +30,9 @@ const bot = new Client({
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MEMBERS
],
});
@@ -51,15 +54,28 @@ const mongouri = mongouritemp;
const { connect } = require('mongoose');
bot.on("guildCreate", guild => {
guild.members.fetch
guild.roles.create({ name: 'Selmer Bot Mod' });
const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here');
let owner = guild.members.cache.fetch(guild.ownerID);
owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the <@&' + role + '> role.');
//const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here');
const server = bot.guilds.cache.get(guild.id);
const owner = server.members.fetch(guild.ownerId).then(function(owner) {
owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the "_Selmer Bot Mod_" role.');
owner.send('To help set up Selmer Bot to work better with your server, use _!setup help_ in a channel Selmer Bot is in!');
});
//Set up the server
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(err => {
if (err) { return console.log(err); }
const dbo = client.db(guild.id).collection('SETUP');
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomebanner': null}]);
});
client.close();
});
//MongoDB Integration end
// let item = items.filter(function (item) { return item.name.toLowerCase() == 'grapes'; });
@@ -83,11 +99,11 @@ fs.readdirSync('./commands')
//Set these two manually because all the seperate games can't be included in the command list (all managed by the 'game' file)
let temp_command = require("./commands/db/econ.js");
let temp_command = require("./commands/db/econ.js");
const { STATE } = require('./commands/db/econ.js');
bot.commands.set('econ', temp_command);
temp_command = require('./commands/db/game.js');
bot.commands.set('game', temp_command);
bot.commands.set('econ', temp_command);
temp_command = require('./commands/db/game.js');
bot.commands.set('game', temp_command);
// const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));;
// const currency = new Discord.Collection();
@@ -136,38 +152,78 @@ bot.on('ready', async () => {
//Button Section
bot.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.isButton()) {
const battlecommandlist = ['ATTACK', 'HEAL', 'DEFEND', 'ITEMS'];
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(err => {
if (battlecommandlist.indexOf(interaction.customId) != -1) {
let current_user = turnManager.getTurn(client, bot, interaction);
current_user.then(function (result) {
const id = result[0];
const doc = result[1];
const threadname = doc.thread;
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
if (interaction.user.id == id) {
await interaction.deferReply();
//Check State
if (docs[0].state == STATE.FIGHTING) {
//Do turn stuff
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
}
//remove the old interation message
interaction.message.delete();
interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`);
} else {
console.log("It's not your turn!");
}
});
});
} //else ifs here
});
client.close();
}
else if (interaction.isCommand()) {
}
});
//Welcome new members
bot.on('guildMemberAdd', async (member) => {
//Check for impartial data
if(member.partial) await member.fetch();
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
const guild = bot.guilds.cache.get(member.guild.id);
client.connect(err => {
let current_user = turnManager.getTurn(client, bot, interaction);
current_user.then(function (result) {
const id = result[0];
const doc = result[1];
const threadname = doc.thread;
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
const dbo = client.db(member.guild.id).collection('SETUP');
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
if (interaction.user.id == id) {
await interaction.deferReply();
dbo.find({_id: 'WELCOME'}).toArray(async (err, docs) => {
var welcomechannel;
if (docs[0].welcomechannel == null) {
welcomechannel = guild.channels.cache.find(channel => channel.name.toLowerCase() === 'welcome');
} else {
welcomechannel = guild.channels.cache.get(docs[0].welcomechannel)
}
//Check State
if (docs[0].state == STATE.FIGHTING) {
//Do turn stuff
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
}
//remove the old interation message
// interaction.message.delete();
interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`);
} else {
console.log("It's not your turn!");
}
});
});
});
if (welcomechannel == null) {
return console.log('No welcome channel detected');
}
await welcome(member, welcomechannel, docs[0].welcomebanner);
})
})
});
@@ -180,6 +236,19 @@ bot.on('messageCreate', (message) => {
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
if (command == 'welcome') {
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('WELCOME')
.setLabel('WELCOME')
.setStyle('PRIMARY')
);
message.channel.send({ components: [row] });
}
//Check if the user has sufficient permission
//Performes the command
//Admin section
@@ -187,14 +256,14 @@ bot.on('messageCreate', (message) => {
else if(bot.commands.has(command) && command != 'ECON') {
//Database access is required, change the inputs
if (command == 'game' || command == 'accept') {
if (command == 'game' || command == 'accept' || command == 'setup') {
bot.commands.get(command).execute(bot, message, args, command, Discord, mongouri, items, xp_collection);
} else {
bot.commands.get(command).execute(message, args, Discord, Client, bot);
}
}
//Catch
//Econ and also the catch statement
else { bot.commands.get('econ').execute(bot, message, args, command, Discord, mongouri, items, xp_collection); }
})