Added the 'game tictactoe' command

This commit is contained in:
ION606
2022-07-01 15:00:52 +03:00
parent f122f84a0c
commit ae63a93940
7 changed files with 329 additions and 107 deletions
+3 -93
View File
@@ -4,6 +4,7 @@ const { MongoClient, ServerApiVersion } = require('mongodb');
const fs = require('fs');
const turnManager = require('./commands/turnManager.js');
const { welcome } = require('./commands/admin/welcome.js');
const { handle_interaction } = require('./commands/interactionhandler.js');
const { exit } = require('process');
const BASE_LVL_XP = 20;
@@ -106,7 +107,7 @@ fs.readdirSync('./commands')
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');
temp_command = require('./commands/games/game.js');
bot.commands.set('game', temp_command);
// const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));;
@@ -162,98 +163,7 @@ bot.on('ready', async () => {
//Button Section
bot.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
const battlecommandlist = ['ATTACK', 'HEAL', 'DEFEND', 'ITEMS', 'ULTIMATE'];
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.IDLE) {
//Do turn stuff
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
}
//remove the old interation message
await interaction.message.delete();
if (interaction.customId.toLowerCase() != 'heal') {
interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`);
}
} else {
console.log("It's not your turn!");
}
});
});
}//else ifs here
});
client.close();
}
//Menu Selection
else if (interaction.isSelectMenu()) {
const id = interaction.customId.substring(0, interaction.customId.indexOf('|'))
const command = interaction.customId.substring(interaction.customId.indexOf('|'), interaction.customId.length - interaction.customId.indexOf('|'))
console.log(command);
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(err => {
console.log(id);
if (id != interaction.user.id) { return; }
let current_user = turnManager.getTurn(client, bot, interaction);
current_user.then(function(result) {
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) {
interaction.customId = 'usepotion';
//Do turn stuff
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
}
interaction.editReply(`<@${interaction.user.id}> used a _${interaction.values[0]}_!`);
//remove the old interation message
await interaction.message.delete();
} else {
console.log("It's not your turn!");
}
});
});
//Get all chars from after "CUSTOM|" to the end of the str
// let name = item.icon.substr(7, item.icon.length - 6);
});
} else if (interaction.customId.toLowerCase().indexOf('|item') != -1) {
}
//menu else ifs here
} //other selection types here
handle_interaction(interaction, mongouri, turnManager, bot, STATE, items, xp_collection);
});