mirror of
https://github.com/ION606/selmerBot.git
synced 2026-06-05 23:06:14 +00:00
Removed the excessive connecting and closing of the MongoDb databases
This commit is contained in:
+10
-13
@@ -18,18 +18,17 @@ async function execute(bot, message, args, command, Discord, mongouri, items, xp
|
|||||||
return message.reply('Only the server owner can do this!');
|
return message.reply('Only the server owner can do this!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// // @ts-ignore
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
if (client.writeConcern || client.writeConcern) {
|
// if (client.writeConcern || client.writeConcern) {
|
||||||
client.close();
|
// client.close();
|
||||||
return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
// return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Initialize
|
bot.mongoconnection.then(async (client) => {
|
||||||
CreateNewCollection(message, client, server, owner.user.id);
|
// if (err) { return console.log(err); }
|
||||||
|
//Initialize
|
||||||
client.connect(err => {
|
CreateNewCollection(message, client, server, owner.user.id);
|
||||||
if (err) { return console.log(err); }
|
|
||||||
|
|
||||||
const db = client.db(server);
|
const db = client.db(server);
|
||||||
const dbo = db.collection('SETUP');
|
const dbo = db.collection('SETUP');
|
||||||
@@ -94,8 +93,6 @@ async function execute(bot, message, args, command, Discord, mongouri, items, xp
|
|||||||
message.reply(temp);
|
message.reply(temp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-26
@@ -32,22 +32,18 @@ function isNum(arg) {
|
|||||||
|
|
||||||
|
|
||||||
function CreateNewCollection(message, client, server, id, opponent = null, game = null) {
|
function CreateNewCollection(message, client, server, id, opponent = null, game = null) {
|
||||||
client.connect(err => {
|
const db = client.db(String(server));
|
||||||
const db = client.db(String(server));
|
const dbo = db.collection(id);
|
||||||
const dbo = db.collection(id);
|
|
||||||
if (err) { return console.log(err); }
|
|
||||||
db.listCollections({name: id})
|
|
||||||
.next(function(err, collinfo) {
|
|
||||||
if (err) { return console.log(err); }
|
|
||||||
if (!collinfo) {
|
|
||||||
message.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
|
|
||||||
let hp_mp = {maxhp: BASE.HP, hp: BASE.HP, maxmp: BASE.MP, mp: BASE.MP}
|
|
||||||
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, gamesettings: {battle: {class: 'none', ultimate: true}}, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
client.close();
|
db.listCollections({name: id})
|
||||||
|
.next(function(err, collinfo) {
|
||||||
|
if (err) { return console.log(err); }
|
||||||
|
if (!collinfo) {
|
||||||
|
message.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
|
||||||
|
let hp_mp = {maxhp: BASE.HP, hp: BASE.HP, maxmp: BASE.MP, mp: BASE.MP}
|
||||||
|
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, gamesettings: {battle: {class: 'none', ultimate: true}}, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -303,15 +299,18 @@ module.exports = {
|
|||||||
const id = message.author.id;
|
const id = message.author.id;
|
||||||
const server = message.guild.id;
|
const server = message.guild.id;
|
||||||
|
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
if (client.writeConcern || client.writeConcern) {
|
// if (client.writeConcern || client.writeConcern) {
|
||||||
client.close();
|
// client.close();
|
||||||
return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
// return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
||||||
}
|
// }
|
||||||
//Initialize if necessary
|
|
||||||
CreateNewCollection(message, client, server, id);
|
|
||||||
|
|
||||||
client.connect(err => {
|
|
||||||
|
bot.mongoconnection.then(async (client) => {
|
||||||
|
|
||||||
|
//Initialize if necessary
|
||||||
|
CreateNewCollection(message, client, server, id);
|
||||||
|
|
||||||
const db = client.db(String(server));
|
const db = client.db(String(server));
|
||||||
const dbo = db.collection(id);
|
const dbo = db.collection(id);
|
||||||
if (err) { return console.log(err); }
|
if (err) { return console.log(err); }
|
||||||
@@ -352,9 +351,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Close the database
|
|
||||||
client.close();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//Battle Updating stuff
|
//Battle Updating stuff
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ function handle_dm(message, bot) {
|
|||||||
if (!message.content.startsWith('!') || message.content.split(' ')[0] == '!startconvo' || message.content.split(' ')[0] == '!endconvo') {
|
if (!message.content.startsWith('!') || message.content.split(' ')[0] == '!startconvo' || message.content.split(' ')[0] == '!endconvo') {
|
||||||
const member = bot.guilds.cache.get(bot.home_server).members.cache.get(message.author.id);
|
const member = bot.guilds.cache.get(bot.home_server).members.cache.get(message.author.id);
|
||||||
|
|
||||||
const client = new MongoClient(bot.mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(async (client) => {
|
||||||
client.connect(async (err) => {
|
// if (err) { return console.log(err); }
|
||||||
if (err) { return console.log(err); }
|
|
||||||
|
|
||||||
const dbo = client.db('main').collection('authorized');
|
const dbo = client.db('main').collection('authorized');
|
||||||
dbo.find({id: message.author}).toArray((err, docs) => {
|
dbo.find({id: message.author}).toArray((err, docs) => {
|
||||||
@@ -24,7 +23,6 @@ function handle_dm(message, bot) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.close();
|
|
||||||
} else if (message.content.indexOf('!premium') != -1) {
|
} else if (message.content.indexOf('!premium') != -1) {
|
||||||
handleInp(bot, message);
|
handleInp(bot, message);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+140
-142
@@ -217,185 +217,183 @@ module.exports ={
|
|||||||
|
|
||||||
|
|
||||||
//#region Setup
|
//#region Setup
|
||||||
const id = message.author.id;
|
const id = message.author.id;
|
||||||
const server = message.guild.id;
|
const server = message.guild.id;
|
||||||
|
|
||||||
// @ts-ignore
|
// // @ts-ignore
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
if (client.writeConcern || client.writeConcern) {
|
// if (client.writeConcern || client.writeConcern) {
|
||||||
client.close();
|
// client.close();
|
||||||
return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
// return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
|
||||||
}
|
// }
|
||||||
|
var client;
|
||||||
const botdb = client.db('B|S' + bot.user.id);
|
await bot.mongoconnection.then((client1) => {
|
||||||
const serverinbotdb = botdb.collection(server);
|
client = client1;
|
||||||
|
});
|
||||||
|
|
||||||
//Initialize if necessary
|
const botdb = client.db('B|S' + bot.user.id);
|
||||||
ecoimport.CreateNewCollection(message, client, server, id);
|
const serverinbotdb = botdb.collection(server);
|
||||||
command = args[0];
|
|
||||||
|
|
||||||
//Check for a second person and create a second database entry if neccessary
|
//Initialize if necessary
|
||||||
if (message.mentions.users.first() != undefined) {
|
ecoimport.CreateNewCollection(message, client, server, id);
|
||||||
ecoimport.CreateNewCollection(message, client, server, message.mentions.users.first().id);
|
command = args[0];
|
||||||
}
|
|
||||||
|
//Check for a second person and create a second database entry if neccessary
|
||||||
|
if (message.mentions.users.first() != undefined) {
|
||||||
|
ecoimport.CreateNewCollection(message, client, server, message.mentions.users.first().id);
|
||||||
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
const db = client.db(String(server));
|
||||||
|
const dbo = db.collection(id);
|
||||||
|
|
||||||
client.connect(err => {
|
//Check if the client is currently in a game and act accordingly
|
||||||
const db = client.db(String(server));
|
|
||||||
const dbo = db.collection(id);
|
|
||||||
if (err) { return console.log(err); }
|
|
||||||
|
|
||||||
//Check if the client is currently in a game and act accordingly
|
|
||||||
//#region Check Game
|
//#region Check Game
|
||||||
dbo.find({"game": {$exists: true}}).toArray(async function(err, docs){
|
dbo.find({"game": {$exists: true}}).toArray(async function(err, docs){
|
||||||
if (err) { return console.log(err); }
|
if (err) { return console.log(err); }
|
||||||
let doc = docs[0];
|
let doc = docs[0];
|
||||||
let game = null;
|
let game = null;
|
||||||
if (doc) { game = doc.game; }
|
if (doc) { game = doc.game; }
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region non-game-specific commands
|
//#region non-game-specific commands
|
||||||
//For TWO+ PLAYER games only!!!
|
//For TWO+ PLAYER games only!!!
|
||||||
if (command == 'accept') {
|
if (command == 'accept') {
|
||||||
//Handle the messages
|
//Handle the messages
|
||||||
if (message.reference == null) { return message.reply("Please reply to a valid battle request message!"); }
|
if (message.reference == null) { return message.reply("Please reply to a valid battle request message!"); }
|
||||||
let mid = message.reference.messageId;
|
let mid = message.reference.messageId;
|
||||||
let msg = await message.channel.messages.fetch(mid);
|
let msg = await message.channel.messages.fetch(mid);
|
||||||
|
|
||||||
//Check if the person actually challenged you
|
//Check if the person actually challenged you
|
||||||
//Get the length of any user tag
|
//Get the length of any user tag
|
||||||
let mentioned = msg.mentions.users.keys();
|
let mentioned = msg.mentions.users.keys();
|
||||||
|
|
||||||
let tag_len = String(mentioned.next().value).length;
|
let tag_len = String(mentioned.next().value).length;
|
||||||
|
|
||||||
//<@tage_len>, <@ --2+tag_len+2+3 = 7+tag_len
|
//<@tage_len>, <@ --2+tag_len+2+3 = 7+tag_len
|
||||||
let other_tag = msg.content.substr(7+tag_len, tag_len);
|
let other_tag = msg.content.substr(7+tag_len, tag_len);
|
||||||
|
|
||||||
const other_discord = msg.mentions.users.get(other_tag);
|
const other_discord = msg.mentions.users.get(other_tag);
|
||||||
|
|
||||||
//Should also check if the player is already playing a game!!!
|
//Should also check if the player is already playing a game!!!
|
||||||
if (!acceptIsValid(bot, other_discord, message, msg, tag_len)) { return; }
|
if (!acceptIsValid(bot, other_discord, message, msg, tag_len)) { return; }
|
||||||
|
|
||||||
//Get the opponent
|
//Get the opponent
|
||||||
const other = db.collection(other_discord.id);
|
const other = db.collection(other_discord.id);
|
||||||
let startPos = msg.content.indexOf('"') + 1;
|
let startPos = msg.content.indexOf('"') + 1;
|
||||||
let newCommand = msg.content.substr(startPos, msg.content.lastIndexOf('"') - startPos);
|
let newCommand = msg.content.substr(startPos, msg.content.lastIndexOf('"') - startPos);
|
||||||
|
|
||||||
|
|
||||||
//#region BOT SECTION
|
//#region BOT SECTION
|
||||||
|
|
||||||
//Store both IDs in the database (for turns)
|
//Store both IDs in the database (for turns)
|
||||||
let name_first = await bot.users.cache.get(id);
|
let name_first = await bot.users.cache.get(id);
|
||||||
let name_second = await bot.users.cache.get(other_discord.id);
|
let name_second = await bot.users.cache.get(other_discord.id);
|
||||||
|
|
||||||
// message.reply(`${first} [${name_first}], ${second} [${name_second}]`); throw 'ERR';
|
// message.reply(`${first} [${name_first}], ${second} [${name_second}]`); throw 'ERR';
|
||||||
const threadname = `${name_first.username} VS ${name_second.username} [${newCommand.toUpperCase()}]`;
|
const threadname = `${name_first.username} VS ${name_second.username} [${newCommand.toUpperCase()}]`;
|
||||||
var newObj = {0: id, 1: other_discord.id, turn: 0, thread: threadname};
|
var newObj = {0: id, 1: other_discord.id, turn: 0, thread: threadname};
|
||||||
|
|
||||||
if (newCommand.replaceAll(" ", "").toLowerCase() == 'tictactoe') { newCommand = 'Tic Tac Toe'; }
|
if (newCommand.replaceAll(" ", "").toLowerCase() == 'tictactoe') { newCommand = 'Tic Tac Toe'; }
|
||||||
|
|
||||||
if (newCommand === 'Tic Tac Toe') {
|
if (newCommand === 'Tic Tac Toe') {
|
||||||
//Create the new board
|
//Create the new board
|
||||||
let newboard = ["", "", "", "", "", "", "", "", ""];
|
let newboard = ["", "", "", "", "", "", "", "", ""];
|
||||||
newObj.board = newboard;
|
newObj.board = newboard;
|
||||||
let symbols;
|
let symbols;
|
||||||
|
|
||||||
/*DOES NOT WORK
|
/*DOES NOT WORK
|
||||||
if (msg.content.lastIndexOf('>') == msg.content.lenth) {
|
if (msg.content.lastIndexOf('>') == msg.content.lenth) {
|
||||||
symbols = ['X', 'O'];
|
symbols = ['X', 'O'];
|
||||||
} else {
|
|
||||||
symbols = msg.content.substring(msg.content.lastIndexOf('>') + 2).split(' ');
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
newObj.symbols = ['X', 'O'];
|
|
||||||
}
|
|
||||||
|
|
||||||
serverinbotdb.insertOne(newObj);
|
|
||||||
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Need this for all 2 player games
|
|
||||||
const result = Initialize(bot, dbo, newCommand, msg, id, other_discord.id, other);
|
|
||||||
|
|
||||||
if (newCommand == 'battle') {
|
|
||||||
result.then(function (thread) {
|
|
||||||
battle.handle(client, dbo, other, bot, thread, 'initalize', mongouri, items, null, xp_collection);
|
|
||||||
});
|
|
||||||
} else if (newCommand == 'Tic Tac Toe') {
|
|
||||||
result.then(function (thread) {
|
|
||||||
ttt.handle(client, db, dbo, other, bot, thread, 'initalize', mongouri, null, xp_collection);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (command == 'quit') {
|
|
||||||
|
|
||||||
const channel = bot.channels.cache.get(message.channel.parentId);
|
|
||||||
//Remove the turn counter from the bot's database
|
|
||||||
serverinbotdb.deleteOne({0: id} || {1: id});
|
|
||||||
if (doc.opponent != null) {
|
|
||||||
// let other = message.guild.members.cache.get(doc.opponent);
|
|
||||||
let other = db.collection(doc.opponent);
|
|
||||||
channel.send(`<@${message.author.id}> has quit a game of "${game}" with <@${doc.opponent}>!`);
|
|
||||||
winGame(client, bot, db, other, xp_collection, message);
|
|
||||||
} else {
|
} else {
|
||||||
loseGame(dbo, xp_collection, message, bot);
|
symbols = msg.content.substring(msg.content.lastIndexOf('>') + 2).split(' ');
|
||||||
channel.send(`<@${message.author.id}> has quit a game of "${game}"!`);
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
newObj.symbols = ['X', 'O'];
|
||||||
}
|
}
|
||||||
else if (command == 'status') {
|
|
||||||
getGame(message, args, db);
|
serverinbotdb.insertOne(newObj);
|
||||||
} else if (command == 'hp' || command == 'mp') {
|
|
||||||
hpmp(message, command, dbo);
|
//#endregion
|
||||||
} else if (command == 'equip') {
|
|
||||||
// equipItem(client, bot, db, dbo, message);
|
|
||||||
equip(message, args, command, dbo, bot, items);
|
|
||||||
} else if (command == 'classes') {
|
//Need this for all 2 player games
|
||||||
presentClasses(message, args[1]);
|
const result = Initialize(bot, dbo, newCommand, msg, id, other_discord.id, other);
|
||||||
|
|
||||||
|
if (newCommand == 'battle') {
|
||||||
|
result.then(function (thread) {
|
||||||
|
battle.handle(client, dbo, other, bot, thread, 'initalize', mongouri, items, null, xp_collection);
|
||||||
|
});
|
||||||
|
} else if (newCommand == 'Tic Tac Toe') {
|
||||||
|
result.then(function (thread) {
|
||||||
|
ttt.handle(client, db, dbo, other, bot, thread, 'initalize', mongouri, null, xp_collection);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
} else if (command == 'quit') {
|
||||||
|
|
||||||
|
const channel = bot.channels.cache.get(message.channel.parentId);
|
||||||
|
//Remove the turn counter from the bot's database
|
||||||
|
serverinbotdb.deleteOne({0: id} || {1: id});
|
||||||
|
if (doc.opponent != null) {
|
||||||
|
// let other = message.guild.members.cache.get(doc.opponent);
|
||||||
|
let other = db.collection(doc.opponent);
|
||||||
|
channel.send(`<@${message.author.id}> has quit a game of "${game}" with <@${doc.opponent}>!`);
|
||||||
|
winGame(client, bot, db, other, xp_collection, message);
|
||||||
|
} else {
|
||||||
|
loseGame(dbo, xp_collection, message, bot);
|
||||||
|
channel.send(`<@${message.author.id}> has quit a game of "${game}"!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command == 'status') {
|
||||||
|
getGame(message, args, db);
|
||||||
|
} else if (command == 'hp' || command == 'mp') {
|
||||||
|
hpmp(message, command, dbo);
|
||||||
|
} else if (command == 'equip') {
|
||||||
|
// equipItem(client, bot, db, dbo, message);
|
||||||
|
equip(message, args, command, dbo, bot, items);
|
||||||
|
} else if (command == 'classes') {
|
||||||
|
presentClasses(message, args[1]);
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region game-specific commands
|
//#region game-specific commands
|
||||||
else {
|
else {
|
||||||
if (command == undefined) { return message.reply("Please specify a game or use _!game help_"); }
|
if (command == undefined) { return message.reply("Please specify a game or use _!game help_"); }
|
||||||
|
|
||||||
//Make change to new name if necessary
|
//Make change to new name if necessary
|
||||||
if (command.replaceAll(" ", "").toLowerCase() == 'tictactoe') { command = 'Tic Tac Toe'; }
|
if (command.replaceAll(" ", "").toLowerCase() == 'tictactoe') { command = 'Tic Tac Toe'; }
|
||||||
|
|
||||||
|
if (game == 'battle' || command == 'battle') {
|
||||||
|
if (!bot.inDebugMode) { return message.reply("This command is currently in development!"); }
|
||||||
|
|
||||||
if (game == 'battle' || command == 'battle') {
|
//Handle sending the request and making sure the user exists here
|
||||||
if (!bot.inDebugMode) { return message.reply("This command is currently in development!"); }
|
let other_discord = message.mentions.users.first();
|
||||||
|
if (other_discord == undefined) {
|
||||||
//Handle sending the request and making sure the user exists here
|
return message.reply(`${args[1]} is not a valid user!`);
|
||||||
let other_discord = message.mentions.users.first();
|
|
||||||
if (other_discord == undefined) {
|
|
||||||
return message.reply(`${args[1]} is not a valid user!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"battle"_. To accept, please reply to this message with _!game accept_`);
|
|
||||||
} else if (game == 'Tic Tac Toe' || command == 'Tic Tac Toe') {
|
|
||||||
let other_discord = message.mentions.users.first();
|
|
||||||
if (other_discord == undefined) {
|
|
||||||
return message.reply(`${args[1]} is not a valid user!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"Tic Tac Toe"_. To accept, please reply to this message with _!game accept_`);
|
|
||||||
} else if (game == 'trivia' || command == 'trivia') {
|
|
||||||
trivia.execute(message, args, Discord, client, bot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"battle"_. To accept, please reply to this message with _!game accept_`);
|
||||||
//Catch statement (invalid command)
|
} else if (game == 'Tic Tac Toe' || command == 'Tic Tac Toe') {
|
||||||
else {
|
let other_discord = message.mentions.users.first();
|
||||||
message.reply(`'${bot.prefix}game ${command}' is not a command!`);
|
if (other_discord == undefined) {
|
||||||
|
return message.reply(`${args[1]} is not a valid user!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"Tic Tac Toe"_. To accept, please reply to this message with _!game accept_`);
|
||||||
|
} else if (game == 'trivia' || command == 'trivia') {
|
||||||
|
trivia.execute(message, args, Discord, client, bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Catch statement (invalid command)
|
||||||
|
else {
|
||||||
|
message.reply(`'${bot.prefix}game ${command}' is not a command!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.close();
|
|
||||||
}, allGames, in_game_redirector
|
}, allGames, in_game_redirector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ for (i in categoriesJSON) {
|
|||||||
|
|
||||||
function changeDB(bot, message, m) {
|
function changeDB(bot, message, m) {
|
||||||
try {
|
try {
|
||||||
const client = new MongoClient(bot.mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(client => {
|
||||||
client.connect(err => {
|
|
||||||
const dbo = client.db(message.guild.id).collection('trivia');
|
const dbo = client.db(message.guild.id).collection('trivia');
|
||||||
//Game Over
|
//Game Over
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
|
|||||||
const singleCommandGames = ['ttt']; // Use when you have more single-player games
|
const singleCommandGames = ['ttt']; // Use when you have more single-player games
|
||||||
const musicCommandList = ['PLAY', 'PAUSE', 'RESUME', 'STOP', 'SKIP'];
|
const musicCommandList = ['PLAY', 'PAUSE', 'RESUME', 'STOP', 'SKIP'];
|
||||||
|
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(async (client) => {
|
||||||
client.connect(async (err) => {
|
|
||||||
|
|
||||||
if (battlecommandlist.indexOf(interaction.customId) != -1) {
|
if (battlecommandlist.indexOf(interaction.customId) != -1) {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
@@ -75,8 +74,6 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
|
|||||||
resolveComplaint(interaction);
|
resolveComplaint(interaction);
|
||||||
} //Button else ifs here
|
} //Button else ifs here
|
||||||
});
|
});
|
||||||
|
|
||||||
client.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Menu Selection
|
//Menu Selection
|
||||||
@@ -85,8 +82,7 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
|
|||||||
// const command = interaction.customId.substring(interaction.customId.indexOf('|'), interaction.customId.length - interaction.customId.indexOf('|'))
|
// const command = interaction.customId.substring(interaction.customId.indexOf('|'), interaction.customId.length - interaction.customId.indexOf('|'))
|
||||||
|
|
||||||
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
|
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(client => {
|
||||||
client.connect(err => {
|
|
||||||
console.log(id);
|
console.log(id);
|
||||||
if (id != interaction.user.id) { return; }
|
if (id != interaction.user.id) { return; }
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -14,9 +14,8 @@ const col_list = {0: '0ed300', 1: 'f6ff00', 2: 'ffa100', 3: 'FF0000'}
|
|||||||
* @param {*} message the message the mod sent (AKA a DISCORD MESSAGE OBJECT)
|
* @param {*} message the message the mod sent (AKA a DISCORD MESSAGE OBJECT)
|
||||||
*/
|
*/
|
||||||
function log(bot, message, command, mentioned, reason, severity) {
|
function log(bot, message, command, mentioned, reason, severity) {
|
||||||
const client = new MongoClient(bot.mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(client => {
|
||||||
client.connect(err => {
|
// if (err) { return console.log(err); }
|
||||||
if (err) { return console.log(err); }
|
|
||||||
|
|
||||||
|
|
||||||
client.db(message.guild.id).collection('SETUP').findOne({_id: 'LOG'}).then((doc) => {
|
client.db(message.guild.id).collection('SETUP').findOne({_id: 'LOG'}).then((doc) => {
|
||||||
|
|||||||
+11
-12
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
-----WEBHOOKS ARE MONITORED AND PROCESSED HERE-----
|
-----WEBHOOKS ARE MONITORED AND PROCESSED HERE-----
|
||||||
https://glitch.com/edit/#!/selmer-bot-listener
|
https://selmer-bot-listener.ion606.repl.co
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,17 +17,17 @@ async function createSubscriptionManual(bot, interaction, id, priceID) {
|
|||||||
//Error Checking (unlikely, but just in case)
|
//Error Checking (unlikely, but just in case)
|
||||||
if (!id) { console.log('....What? How?'); return interaction.editReply("Uh oh, something happened with the Stripe Discord ID check, please contact support!"); }
|
if (!id) { console.log('....What? How?'); return interaction.editReply("Uh oh, something happened with the Stripe Discord ID check, please contact support!"); }
|
||||||
|
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
new Promise(async function(resolve, reject) {
|
new Promise(async function(resolve, reject) {
|
||||||
client.connect(async (err) => {
|
bot.mongoconnection.then(async (client) => {
|
||||||
if (err) { return console.log(err); }
|
// if (err) { return console.log(err); }
|
||||||
|
|
||||||
const dbo = client.db('main').collection('authorized');
|
const dbo = client.db('main').collection('authorized');
|
||||||
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
||||||
var userID;
|
var userID;
|
||||||
|
|
||||||
if (doc != undefined) {
|
if (doc != undefined) {
|
||||||
client.close();
|
// client.close();
|
||||||
|
|
||||||
reject(`An account with the tag <@${id}> already exists!`);
|
reject(`An account with the tag <@${id}> already exists!`);
|
||||||
} else {
|
} else {
|
||||||
@@ -37,7 +37,7 @@ async function createSubscriptionManual(bot, interaction, id, priceID) {
|
|||||||
userID = stripeUser.id;
|
userID = stripeUser.id;
|
||||||
|
|
||||||
//Add to the database (I have to wait for the insertion)
|
//Add to the database (I have to wait for the insertion)
|
||||||
await dbo.insertOne({stripeID: userID, discordID: id, paid: false, startDateUTC: null, tier: 0}).then(() => { client.close(); resolve(userID); });
|
await dbo.insertOne({stripeID: userID, discordID: id, paid: false, startDateUTC: null, tier: 0}).then(() => { /*client.close();*/ resolve(userID); });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -87,10 +87,10 @@ async function changeSubscriptionManual(bot, message) {
|
|||||||
//Just in case
|
//Just in case
|
||||||
if (!id) { return console.log('....What? How?'); }
|
if (!id) { return console.log('....What? How?'); }
|
||||||
|
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
new Promise(async function(resolve, reject) {
|
new Promise(async function(resolve, reject) {
|
||||||
client.connect(async (err) => {
|
bot.mongoconnection.then(async (client) => {
|
||||||
if (err) { return console.log(err); }
|
// if (err) { return console.log(err); }
|
||||||
|
|
||||||
const dbo = client.db('main').collection('authorized');
|
const dbo = client.db('main').collection('authorized');
|
||||||
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
||||||
@@ -98,11 +98,10 @@ async function changeSubscriptionManual(bot, message) {
|
|||||||
|
|
||||||
if (doc != undefined) {
|
if (doc != undefined) {
|
||||||
userID = doc.stripeID;
|
userID = doc.stripeID;
|
||||||
client.close();
|
// client.close();
|
||||||
resolve(userID);
|
resolve(userID);
|
||||||
} else {
|
} else {
|
||||||
client.close();
|
// client.close();
|
||||||
|
|
||||||
reject(`No user with the ID of <@${message.author.id}>`);
|
reject(`No user with the ID of <@${message.author.id}>`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ if (process.env.MONGODB_URI) {
|
|||||||
}
|
}
|
||||||
const mongouri = mongouritemp;
|
const mongouri = mongouritemp;
|
||||||
bot.mongouri = mongouri;
|
bot.mongouri = mongouri;
|
||||||
|
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||||
|
bot.mongoconnection = client.connect();
|
||||||
|
|
||||||
const { connect } = require('mongoose');
|
const { connect } = require('mongoose');
|
||||||
|
|
||||||
//#endregion MongoDB Integration end
|
//#endregion MongoDB Integration end
|
||||||
@@ -148,15 +151,12 @@ let items;
|
|||||||
|
|
||||||
bot.on('ready', async () => {
|
bot.on('ready', async () => {
|
||||||
//Make then copy the shop
|
//Make then copy the shop
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(client => {
|
||||||
client.connect(err => {
|
|
||||||
const shop = client.db("main").collection("shop");
|
const shop = client.db("main").collection("shop");
|
||||||
shop.find().toArray(function(err, itemstemp) {
|
shop.find().toArray(function(err, itemstemp) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
items = [...itemstemp];
|
items = [...itemstemp];
|
||||||
|
|
||||||
client.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Srt status and Activity (idle and listening to !help)
|
//Srt status and Activity (idle and listening to !help)
|
||||||
@@ -210,15 +210,11 @@ bot.on("guildCreate", guild => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Set up the server
|
//Set up the server
|
||||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
bot.mongoconnection.then(client => {
|
||||||
client.connect(err => {
|
|
||||||
if (err) { return console.log(err); }
|
|
||||||
|
|
||||||
const dbo = client.db(guild.id).collection('SETUP');
|
const dbo = client.db(guild.id).collection('SETUP');
|
||||||
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomemessage': null, 'welcomebanner': null}, {_id: 'LOG', 'keepLogs': false, 'logchannel': null, 'severity': 0}]);
|
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomemessage': null, 'welcomebanner': null}, {_id: 'LOG', 'keepLogs': false, 'logchannel': null, 'severity': 0}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -229,11 +225,9 @@ bot.on('guildMemberAdd', async (member) => {
|
|||||||
//Check for impartial data
|
//Check for impartial data
|
||||||
if(member.partial) await member.fetch();
|
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);
|
const guild = bot.guilds.cache.get(member.guild.id);
|
||||||
|
|
||||||
client.connect(err => {
|
bot.mongoconnection.then(client => {
|
||||||
const dbo = client.db(member.guild.id).collection('SETUP');
|
const dbo = client.db(member.guild.id).collection('SETUP');
|
||||||
|
|
||||||
dbo.find({_id: 'WELCOME'}).toArray(async (err, docs) => {
|
dbo.find({_id: 'WELCOME'}).toArray(async (err, docs) => {
|
||||||
@@ -255,7 +249,7 @@ bot.on('guildMemberAdd', async (member) => {
|
|||||||
|
|
||||||
|
|
||||||
bot.on('messageCreate', (message) => {
|
bot.on('messageCreate', (message) => {
|
||||||
|
bot.guilds.cache.get('930148608400035860').members.cache.get('358402930191106049');
|
||||||
//DM SECTION
|
//DM SECTION
|
||||||
if (message.channel.type === "DM") {
|
if (message.channel.type === "DM") {
|
||||||
return handle_dm(message, bot);
|
return handle_dm(message, bot);
|
||||||
|
|||||||
Reference in New Issue
Block a user