diff --git a/commands/Selmer Specific/msgLevels.js b/commands/Selmer Specific/msgLevels.js index 06f0698..ef6f79a 100644 --- a/commands/Selmer Specific/msgLevels.js +++ b/commands/Selmer Specific/msgLevels.js @@ -13,13 +13,15 @@ async function setCard(bot, interaction) { function textToLevels(bot, message, xp_list) { + if (!bot.inDebugMode && message.guild.id == bot.home_server) { return; } + const author = message.author; // doc.xp + (BASE.XP * doc.rank) bot.mongoconnection.then((client) => { const serverOpts = client.db(message.guild.id).collection('SETUP'); serverOpts.findOne({_id: "LEVELING"}).then((doc) => { if (!doc) { - serverOpts.insertOne({_id: "LEVELING", enabled: false, card: undefined, text: undefined}); + serverOpts.insertOne({_id: "LEVELING", enabled: false, card: undefined, text: undefined, col: "#FFFFFF"}); const server = bot.guilds.cache.get(message.guild.id); server.members.fetch(message.guild.ownerId).then(function(owner) { // Implement `setup leveling enable` @@ -29,7 +31,7 @@ function textToLevels(bot, message, xp_list) { const dbo = client.db(message.guild.id).collection(author.id); dbo.findOne({"balance": {$exists: true}}).then((doc) => { const newXp = doc.xp + Math.ceil((BASE.XP * doc.rank) / 4); - addxp(message, dbo, newXp, xp_list, true); + addxp(bot, message, dbo, newXp, xp_list, true); }); } }); diff --git a/commands/Selmer Specific/replies.js b/commands/Selmer Specific/replies.js new file mode 100644 index 0000000..39faa68 --- /dev/null +++ b/commands/Selmer Specific/replies.js @@ -0,0 +1,54 @@ +const Discord = require('discord.js'); + +/** + * @description a fun little easter egg mention function + * @param {Discord.Message} message + */ +function replies(bot, message) { + const c = message.content.replace(`<@${bot.user.id}>`, "").toLowerCase().trim(); + var s = ""; + + switch (c) { + case "hi": + case "hello": + case "hya": + s = "Hi there! :wave:"; + break; + + case "i love you": + s = "seek help :smile:"; + break; + + case "chicken nuggets": + s = "nom nom nom"; + break; + + case "chimkin nungits": + s = "marry me :heart_eyes:"; + break; + + case "😉": + s = ":wink:"; + break; + + case "😜": + s = "😜"; + break; + + case "🍆": + case "🍑": + case "🍌": + s = "❌"; + break; + + case "💩": + s = "🤮"; + break; + + default: s = "I'm not sure what that means! Please use `/help` for a comprehensive list of commands!\n\n_PS - If you want to make full use of the bot's AI capabilities, consider Selmer Bot Premium. See more at https://selmerbot.com/premium _"; + } + + message.reply(s).catch(() => { message.channel.send(s); }); +} + +module.exports = replies; \ No newline at end of file diff --git a/commands/Selmer Specific/repo.js b/commands/Selmer Specific/repo.js index 5c9e028..cd13e4f 100644 --- a/commands/Selmer Specific/repo.js +++ b/commands/Selmer Specific/repo.js @@ -18,7 +18,7 @@ module.exports = { new MessageButton() .setStyle("LINK") - .setURL("https://www.selmerbot.com/") + .setURL("https://selmerbot.com/") .setLabel("Website"), new MessageButton() diff --git a/commands/Selmer Specific/tuto.js b/commands/Selmer Specific/tuto.js index cc6adc8..e64b0e8 100644 --- a/commands/Selmer Specific/tuto.js +++ b/commands/Selmer Specific/tuto.js @@ -12,7 +12,7 @@ const tutoText = [ "__**SELMER SPECIFIC**__\nThese commands will probably be found nowhere else\nThese include quotes (For legal reasons I have to state they aren't real quotes, mostly), as well as varius other things I based on good old Selmer\n\n__***COMMANDS***__\narrow, extracredit, tuto, profile, quotes", "__**MISCELLANEOUS**__\nThese are the commands that are not really in any of the other categories. Don't be fooled, these are actually some of the most useful commands Selmer Bot has to offer. From playing music to web scraping to memes, I'm sure Selmer Bot has what you're looking for\n\n__***COMMANDS***__\nhelp, kareoke, link, meme, pickupline, audio, react, scrape, stocks, crypto", "__**DM COMMANDS**__\nThese commands will only work in DM's. All these commands will only work with Selmer Bot Premium (it's on the next page).\nThese features include Reminders (AKA a calendar) and Selmer Bot's own chat AI\n\n__***COMMANDS***__\nchat, startconvo, endconvo, premium", - "__**SELMER BOT PREMIUM**__\nUse an AI chat, complete with semi-accurate IRL data, have Selmer Bot remind you of events with an easy-to-use interface and even a clickable calendar on the Selmer Bot website (_www.selmerbot.com_)\n\n__***COMMANDS***__\npremium, premium buy, premium manage, reminders", + "__**SELMER BOT PREMIUM**__\nUse an AI chat, complete with semi-accurate IRL data, have Selmer Bot remind you of events with an easy-to-use interface and even a clickable calendar on the Selmer Bot website (_ https://selmerbot.com _)\n\n__***COMMANDS***__\npremium, premium buy, premium manage, reminders", "__**Thank you for completing the Selmer Bot Tutorial**__\n\nTry out Selmer Bot's features, play the games and most importantly, have fun\n\n-The Selmer Bot Team AKA ION606" ]; @@ -29,7 +29,7 @@ function postEmbd(bot, interaction, page, refered) { te.setAuthor(author) .setTitle("Selmer Bot Tutorial") .setDescription(tutoText[page]) - .setURL('https://www.selmerbot.com/') + .setURL('https://selmerbot.com/') .setFooter({ text: `Page ${page + 1}` }); @@ -66,9 +66,9 @@ function postEmbd(bot, interaction, page, refered) { row.addComponents(prevbtn, nextbtn); if (page > 0 || refered) { - interaction.update({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [te], components: [row] }); + interaction.update({ content: '_Note: To see a full list of reminder stats visit selmerbot.com _', embeds: [te], components: [row] }); } else { - interaction.channel.send({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [te], components: [row] }); + interaction.channel.send({ content: '_Note: To see a full list of reminder stats visit selmerbot.com _', embeds: [te], components: [row] }); } } diff --git a/commands/admin/setup.js b/commands/admin/setup.js index 7838c4c..bb2b34b 100644 --- a/commands/admin/setup.js +++ b/commands/admin/setup.js @@ -3,7 +3,8 @@ const { MongoClient, ServerApiVersion } = require('mongodb'); const { Constants } = require('discord.js'); const { CreateNewCollection } = require("../db/econ"); const { checkRole } = require('./verify.js'); -// const fetch = require('node-fetch'); +const fetch = require('node-fetch'); +const help = require('../misc/help.js'); async function execute(interaction, Discord, Client, bot) { @@ -27,21 +28,14 @@ async function execute(interaction, Discord, Client, bot) { for (let i = 0; i < args.length; i++) { try { const command = args[i].name; - - // if (!command) { - // interaction.reply('Please use the following format _!setup help _'); - // } else if (command == 'welcome_channel') { - // if (args.length != 2) { return interaction.reply('The command format is _!setup welcome_channel _'); } - // setWelcomeChannel(dbo, message, args[1]); const channel = args[i].channel; dbo.updateOne({welcomechannel: {$exists: true}}, {$set: {welcomechannel: `${channel.id}`}}); interaction.reply({content: `Set ${channel} as the new welcome channel`, ephemeral: true}) } else if (command == 'welcome_message') { - // if (args.length < 2) { return interaction.reply('The command format is _!setup welcome\\_message_\nUse _{sn}_ to insert the server name, _{un}_ to insert the user name, and _{ut}_ to insert the user tag\nExample: _!setup welcome\\_message Welcome to {sn} Sir {un}#{ut}_'); } const msg = args[i].value; if (msg.length > 30 || msg.length < 1) { return interaction.reply({content: 'Please specify a welcome message between 0 and 30 characters!', ephemeral: true}); } @@ -55,8 +49,6 @@ async function execute(interaction, Discord, Client, bot) { interaction.reply({content: `Toggled log keeping to ${keeplogs}. Please use _!setup log_channel_ to choose the log channel`, ephemeral: true}); } else if (command == 'log_channel') { - // if (args.length != 2) { return message.reply('Please specify a parameter\nExample: _!setup log\\_channel true_'); } - const channel = args[i].channel; if (!channel) { return interaction.reply({content: 'The specified channel does not exist!', ephemeral: true}); } @@ -72,7 +64,7 @@ async function execute(interaction, Discord, Client, bot) { interaction.reply({content: `Severity updated to ${tier}`, ephemeral: true}); } - else if (command == 'announcement_role') { + else if (command == 'ping_role') { const role = args[i].value; // if (message.mentions.roles.first() == undefined) { // return message.reply("Please mention a role (_!setup announcement\\_role **@role**_)\n_Note: Selmer Bot does NOT ping the @everyone role_"); @@ -82,11 +74,12 @@ async function execute(interaction, Discord, Client, bot) { interaction.reply({content: `Role updated to ${role}`, ephemeral: true}); } - else if (command == "announcement_channel") { + else if (command == "ping_channel") { const channel = args[i].channel; if (!channel) { return interaction.reply({content: 'The specified channel does not exist!', ephemeral: true}); } dbo.updateOne({_id: 'announcement'}, { $set: { 'channel': channel.id } }); + interaction.reply({content: `Channel set to ${channel}`, ephemeral: true}); } else if (command == "add_mod_role") { dbo.findOne({_id: "roles"}).then((doc) => { @@ -104,33 +97,56 @@ async function execute(interaction, Discord, Client, bot) { interaction.reply({ content: "Role removed!", ephemeral: true }); } else if (command == "welcome_banner") { - const response = await fetch(interaction.options.data[0].attachment.attachment); + const attachement_url = interaction.options.data[0].attachment.attachment; + const response = await fetch(attachement_url); const arrayBuffer = await response.arrayBuffer(); const imgbfr = Buffer.from(arrayBuffer); dbo.updateOne({_id: 'WELCOME'}, {$set: {welcomebanner: imgbfr.toString('base64')}}); - interaction.reply({ content: "Banner updated!", ephemeral: true }); + interaction.reply({ content: `Banner updated to ${attachement_url}`, ephemeral: true}); } else if (command == "welcome_text_color") { const reg = /^#[0-9A-F]{6}$/i; const newCol = interaction.options.data[0].value; if (reg.test(newCol)) { dbo.updateOne({_id: 'WELCOME'}, {$set: {welcometextcolor: newCol}}); - interaction.reply("Color updated!"); + interaction.reply({content: `Color updated to ${newCol} (https://www.color-hex.com/color/${newCol.substring(1)})`, ephemeral: true}); } else { - interaction.reply("Please chose a valid hex color"); + interaction.reply("Please chose a valid hex color\nYou can find colors here: https://www.color-hex.com/"); } } else if (command == "toggle_leveling") { - dbo.updateOne({_id: 'LEVELING'}, {$set: {enabled: interaction.options.data[0].value}}); + const tog = interaction.options.data[0].value; + dbo.updateOne({_id: 'LEVELING'}, {$set: {enabled: tog}}); + interaction.reply({content: "Turned leveling " + (tog) ? "ON" : "OFF", ephemeral: true}); } else if (command == "leveling_banner") { - const response = await fetch(interaction.options.data[0].attachment.attachment); + const level_banner = interaction.options.data[0].attachment.attachment; + const response = await fetch(level_banner); const arrayBuffer = await response.arrayBuffer(); const imgbfr = Buffer.from(arrayBuffer); dbo.updateOne({_id: 'LEVELING'}, {$set: {card: imgbfr.toString('base64')}}); + interaction.reply({content: `Updated leveling banner to ${level_banner}`, ephemeral: true}); } else if (command == "leveling_text") { dbo.updateOne({_id: 'LEVELING'}, {$set: {text: interaction.options.data[0].value}}); + interaction.reply({content: `Updated leveling text to ${interaction.options.data[0].value}`, ephemeral: true}); + } + else if (command == "leveling_color") { + const reg = /^#[0-9A-F]{6}$/i; + const newCol = interaction.options.data[0].value; + if (reg.test(newCol)) { + dbo.updateOne({_id: 'LEVELING'}, {$set: {col: newCol}}); + interaction.reply({content: `Color updated to ${newCol} (https://www.color-hex.com/color/${newCol.substring(1)})`, ephemeral: true}); + } else { + interaction.reply("Please chose a valid hex color\nYou can find colors here: https://www.color-hex.com/"); + } + } + else if (command == "help") { + if (interaction.options.data[0].value) { + help.execute(interaction, Discord, Client, bot); + } else { + interaction.reply({content: 'https://docs.selmerbot.com/setup', ephemeral: true}); + } } else { interaction.reply({content: "Please chose a valid option", ephemeral: true}); @@ -167,19 +183,20 @@ module.exports = { execute, options: [ {name: 'welcome_channel', description: 'Sets the channel for welcome messages', type: Constants.ApplicationCommandOptionTypes.CHANNEL }, - {name: 'welcome_message', description: 'Sets the welcome message, Use {un} for username, {ut} for user tag and {sn} for server name', type: Constants.ApplicationCommandOptionTypes.STRING }, + {name: 'welcome_message', description: 'Use {un}, {ud}, {ut}, and {sn} for username, user descriminator, user tag, and server name', type: Constants.ApplicationCommandOptionTypes.STRING }, {name: 'welcome_banner', description: 'Sets the welcome banner', type: Constants.ApplicationCommandOptionTypes.ATTACHMENT}, {name: 'welcome_text_color', description: 'Sets the welcome banner text color', type: Constants.ApplicationCommandOptionTypes.STRING}, {name: 'keep_logs', description: 'Toggles logging', type: Constants.ApplicationCommandOptionTypes.BOOLEAN }, {name: 'log_channel', description: 'Sets the logging channel', type: Constants.ApplicationCommandOptionTypes.CHANNEL }, {name: 'log_severity', description: 'Sets the logging Severity (logs this/lower tiers)', type: Constants.ApplicationCommandOptionTypes.STRING, choices: [{name: 'none', value: 'none'}, {name: 'low', value: 'low'}, {name: 'medium', value: 'medium'}, {name: 'high', value: 'high'}] }, - {name: 'announcement_role', description: 'Sets the role to be pinged for reminders', type: Constants.ApplicationCommandOptionTypes.ROLE}, - {name: 'announcement_channel', description: 'Sets the channel for reminders', type: Constants.ApplicationCommandOptionTypes.CHANNEL}, + {name: 'ping_role', description: 'Sets the role to be pinged for reminders', type: Constants.ApplicationCommandOptionTypes.ROLE}, + {name: 'ping_channel', description: 'Sets the channel for reminders', type: Constants.ApplicationCommandOptionTypes.CHANNEL}, {name: 'add_mod_role', description: 'Make a role into an admin role for Selmer Bot, able to execute ALL Selmer Bot commands', type: Constants.ApplicationCommandOptionTypes.ROLE}, {name: 'remove_mod_role', description: 'Remove a Selmer Bot moderation role', type: Constants.ApplicationCommandOptionTypes.ROLE}, {name: 'toggle_leveling', description: 'Enable or Disable the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN}, - {name: 'leveling_banner', description: 'Set the card background for the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN}, - {name: 'leveling_text', description: 'Set the card text for the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN}, - // {name: 'help', description: 'gets help with setup commands', type: Constants.ApplicationCommandOptionTypes.STRING, choices: [{name: 'welcome', value: 'welcome'}, {name: 'logs', value: 'logs'}, {name: 'announcement', value: 'announcement'}]} + {name: 'leveling_banner', description: 'Set the card background for the leveling system', type: Constants.ApplicationCommandOptionTypes.ATTACHMENT}, + {name: 'leveling_text', description: 'Use {un}, {ud}, {ut}, {sn}, and {r} for username, descriminator, user tag, server name, and rank', type: Constants.ApplicationCommandOptionTypes.STRING}, + {name: 'leveling_color', description: 'Set the card text color for the leveling system', type: Constants.ApplicationCommandOptionTypes.STRING}, + {name: 'help', description: 'in-app?', type: Constants.ApplicationCommandOptionTypes.BOOLEAN} ] } \ No newline at end of file diff --git a/commands/admin/welcome.js b/commands/admin/welcome.js index 74c9af0..0587bab 100644 --- a/commands/admin/welcome.js +++ b/commands/admin/welcome.js @@ -3,34 +3,55 @@ const fetch = require('node-fetch'); const { GuildMember } = require('discord.js'); -function formatMessage(member, welcomemessage) { +function formatMessage(member, welcomemessage, isLvl, rank = null) { return new Promise((resolve, reject) => { - let text = `Welcome to ${member.guild.name} ${member.user.tag}!`; - if (welcomemessage != null) { - text = welcomemessage; - text = text.replace('{sn}', member.guild.name); - text = text.replace('{un}', member.user.username); - text = text.replace('{ut}', member.user.discriminator); + let text; + if (!isLvl) { + text = `Welcome to ${member.guild.name} ${member.user.tag}!`; + if (welcomemessage != null) { + text = welcomemessage; + text = text.replace('{sn}', member.guild.name); + text = text.replace('{un}', member.user.username); + text = text.replace('{ud}', member.user.discriminator); + text = text.replace('{ut}', member.user.tag); + } + } else { + text = `Congradulations ${member.user.tag} for reaching rank ${rank}!`; + + if (welcomemessage != null) { + text = welcomemessage; + text = text.replace('{sn}', member.guild.name); + text = text.replace('{un}', member.user.username); + text = text.replace('{ud}', member.user.discriminator); + text = text.replace('{ut}', member.user.tag); + text = text.replace('{r}', rank); + } } resolve(text); }); } + /** * @param {GuildMember} member * @param {*} welcomeChannel */ -async function welcome(member, welcomeChannel, welcomemessage, welcomebanner, welcomeTextCol) { - formatMessage(member, welcomemessage).then(async (wmsg) => { +async function welcome(member, welcomeChannel, welcomemessage, welcomebanner, welcomeTextCol, isLvl = false, rank = null) { + formatMessage(member, welcomemessage, isLvl, rank).then(async (wmsg) => { const width = 1024; const height = 500; const usernameText = `${wmsg}`; const memberCountText = `You are member ${member.guild.memberCount}`; + + var uSize = 55 - Math.round(wmsg.length/2); + + if (uSize < 5) { uSize = 5; } + const username = ` ${usernameText} diff --git a/commands/db/econ.js b/commands/db/econ.js index 0a63560..fcaea6a 100644 --- a/commands/db/econ.js +++ b/commands/db/econ.js @@ -3,6 +3,7 @@ const { MongoClient, ServerApiVersion } = require('mongodb'); const { Collection, Client, Formatters, Intents, Interaction } = require('discord.js'); const { CLIENT_ODBC } = require('mysql/lib/protocol/constants/client'); const { time } = require('@discordjs/builders'); +const { welcome } = require('../admin/welcome.js'); let currencySymbol = '$'; @@ -46,7 +47,12 @@ function CreateNewCollection(interaction, client, server, id, opponent = null, g } -function addxp(interaction, dbo, amt, xp_list, noPing = false) { + +/** + * @param {Interaction} interaction + * @returns + */ +function addxp(bot, interaction, dbo, amt, xp_list, noPing = false) { if (!isNum(amt)) { return console.log("This isn't a number...."); } dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) { @@ -55,6 +61,7 @@ function addxp(interaction, dbo, amt, xp_list, noPing = false) { temp = doc[0]; let rank = temp.rank + 1; //The table starts at rank 0, the user starts at rank 1 const txp = amt; /*temp.xp + amt; // This part was used before the xp check was made in the 'work' function */ + //If the rank is less than 100, you can still advance if (rank < 101) { let needed = xp_list.get(rank); @@ -85,7 +92,21 @@ function addxp(interaction, dbo, amt, xp_list, noPing = false) { user = interaction.author; } - interaction.channel.send('Congradulations <@' + user.id + '> for reaching rank ' + String(rank) + '!'); + if (bot) { + bot.mongoconnection.then((client) => { + const sbo = client.db(interaction.guildId).collection('SETUP'); + sbo.findOne({_id: 'LEVELING'}).then((doc) => { + if (!doc || !doc.card) { + return interaction.channel.send('Congradulations <@' + user.id + '> for reaching rank ' + String(rank) + '!'); + } + const member = interaction.guild.members.cache.get((interaction.user) ? interaction.user.id : interaction.member.id); + + welcome(member, interaction.channel, doc.text, doc.card, doc.col, true, String(rank)); + }); + }); + } else { + interaction.channel.send('Congradulations <@' + user.id + '> for reaching rank ' + String(rank) + '!'); + } } } else { if (!noPing) { @@ -175,7 +196,7 @@ function buy(id, interaction, dbo, shop, xp_list) { var newObj = { name: item.name, cost: item.cost, icon: item.icon, sect: item.sect}; - addxp(interaction, dbo, Math.ceil(item.cost * 1.2), xp_list); + addxp(bot, interaction, dbo, Math.ceil(item.cost * 1.2), xp_list); dbo.find(newObj, {$exists: true}).toArray(function(err, doc) { if(String(doc)) { @@ -193,7 +214,7 @@ function buy(id, interaction, dbo, shop, xp_list) { //FIXME -function sell(id, interaction, dbo, shop, xp_list) { +function sell(bot, id, interaction, dbo, shop, xp_list) { const args = interaction.options.data; const query = args.filter((arg) => { return (arg.name == 'item'); })[0].value; var num = args.filter((arg) => { return (arg.name == 'amount'); })[0].value; @@ -229,7 +250,7 @@ function sell(id, interaction, dbo, shop, xp_list) { dbo.updateOne({"balance": {$exists: true}}, { $set: { balance: currentBal + amountSoldFor }}); }); - addxp(interaction, dbo, Math.ceil(functional_item.cost * 1.2), xp_list); + addxp(bot, interaction, dbo, Math.ceil(functional_item.cost * 1.2), xp_list); interaction.reply(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`) .catch((err) => { @@ -244,7 +265,7 @@ function sell(id, interaction, dbo, shop, xp_list) { } -function work(dbo, interaction, xp_list) { +function work(bot, dbo, interaction, xp_list) { let fulldate = new Date(); let date = fulldate.getDate(); dbo.find({"lastdayworked": {$exists: true}}).toArray(function(err, doc) { @@ -265,7 +286,8 @@ function work(dbo, interaction, xp_list) { //Update the amount to the new TOTAL balance dbo.updateOne({"balance": {$exists: true}}, { $set: { balance: doc[0].balance + amt, lastdayworked: date }}); - addxp(interaction, dbo, xp_earned, xp_list); + + addxp(bot, interaction, dbo, xp_earned, xp_list); interaction.reply(`<@${interaction.user.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`).catch((err) => { interaction.channel.send(`<@${interaction.user.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`) }); @@ -360,27 +382,17 @@ module.exports = { currencySymbol = bot.currencysymbolmmain; - /*/test area - if (command == 'xp' || command == 'adbal') { - //Selmer Dev only command - if (message.member.roles.cache.has('944048889038774302')) { - if (command == 'xp') { - return addxp(message, dbo, Number(args[0]), xp_list); - } - } - }*/ - //Command Area if(command == 'init') { //Add security check here // init.execute(bot, message, args, command, dbo, Discord, connect); return; } else if (command == 'buy') { - buy(id, interaction, dbo, items, xp_list); + buy(bot, id, interaction, dbo, items, xp_list); } else if (command == 'shop') { getShop(interaction, items, bot); } else if (command == 'work') { - work(dbo, interaction, xp_list); + work(bot, dbo, interaction, xp_list); } else if (command == 'rank') { rank(dbo, interaction, xp_list); } else if (command == 'inventory') { @@ -388,7 +400,7 @@ module.exports = { } else if (command == 'balance') { getBalance(dbo, interaction); } else if (command == 'sell') { - sell(id, interaction, dbo, items, xp_list); + sell(bot, id, interaction, dbo, items, xp_list); } else { interaction.reply(`${command} is not a command`).catch((err) => { interaction.channel.send(`${command} is not a command`); diff --git a/commands/games/external_game_functions.js b/commands/games/external_game_functions.js index 4a87c43..3f5e562 100644 --- a/commands/games/external_game_functions.js +++ b/commands/games/external_game_functions.js @@ -31,7 +31,7 @@ function loseGame(user_dbo, xp_collection, interaction, bot = null) { } //Update the player's xp - addxp(interaction, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection); + addxp(bot, interaction, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection); user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, 'hpmp.hp': doc.hpmp.maxhp, 'hpmp.mp': doc.hpmp.maxmp }}); resolve(addbal); diff --git a/commands/misc/help.js b/commands/misc/help.js index 6dad056..621a1ea 100644 --- a/commands/misc/help.js +++ b/commands/misc/help.js @@ -17,14 +17,15 @@ module.exports ={ if (spec == 'econ') { let temp = "***Selmer Bot Commands (Econ):***\n"; temp += bot.commands.get('econ').econHelp(); - temp += `\n\n(remember to use _'${bot.prefix}'_ before the command!)`; + temp += `\n\n(remember to use \`/\` before the command!)`; return interaction.reply({ content: temp, ephemeral: true }); } else if (spec == 'game') { let temp = "***Selmer Bot Commands (Games):***\n"; temp += bot.commands.get('game').allGames.join(", "); - temp += `\n\n_Note: due to how complicated this feature is, it will not be migrated to slash commands for now_`; + // temp += `\n\n_Note: due to how complicated this feature is, it will not be migrated to slash commands for now_`; + temp += `\n\n(remember to use \'/\' before the command!)`; return interaction.reply({ content: temp, ephemeral: true }); } @@ -39,8 +40,8 @@ module.exports ={ temp += modHelp(); //Uses a different format, only the server owner can use it - temp += '\n_setup_ - ***SERVER OWNER ONLY*** - use _!setup help_\n'; - temp += `\n\n(remember to use _'${bot.prefix}'_ before the command!)`; + temp += '\n_setup_ - ***SERVER OWNER ONLY*** - use \`setup help\`\n'; + temp += `\n\n(remember to use \`/\` before the command!)`; return interaction.reply({ content: temp, ephemeral: true }); } @@ -55,10 +56,10 @@ module.exports ={ bot.commands.forEach((comm) => { if (comm.name != 'verify') { if (comm.name == 'econ') { - temp += `**econ** - use _!help econ_\n`; + temp += `**econ** - use \`/help econ\`\n`; } else if (comm.name == 'game') { - temp += `**games** - use _!help game_\n`; + temp += `**games** - use \`/help game\`\n`; } else { if (comm.name && comm.description && !noPostList.includes(comm.name)) { @@ -68,16 +69,18 @@ module.exports ={ } }); - temp += '**admin/moderation commands** - use !help admin\n'; + temp += '**admin/moderation commands** - use `/help admin`\n'; //Selmer Specific temp += '\n__**Selmer\'s \\*Special\\* Commands**__\n' sList.forEach((commName) => { const comm = bot.commands.get(commName); - temp += `${comm.name.toLowerCase()} - _${comm.description}_\n`; + if (comm && comm.name && comm.description) { + temp += `${comm.name.toLowerCase()} - _${comm.description}_\n`; + } }) - temp += `\n_(remember to use '${bot.prefix}' before the command!)_`; + temp += `\n_(remember to use \`/\` before the command!)_`; interaction.reply({ content: temp, ephemeral: true }); }, diff --git a/commands/premium/chat.js b/commands/premium/chat.js index 4d4b67a..4148463 100644 --- a/commands/premium/chat.js +++ b/commands/premium/chat.js @@ -24,7 +24,8 @@ async function messageExists(message) { async function getResponse(convo, bot) { - const response = await bot.openai.createCompletion({ + try { + const response = await bot.openai.createCompletion({ model: "text-davinci-002", prompt: convo, temperature: 0.9, @@ -36,6 +37,11 @@ async function getResponse(convo, bot) { }); return response; + } catch (err) { + console.error(err); + return false; + } + } async function convoManager(clientinp, bot, message) { @@ -78,6 +84,10 @@ async function convoManager(clientinp, bot, message) { //Get the response const r = await getResponse(convo, bot); + if (!r) { + return message.channel.send("Uh oh! There's been an error! Please contact support \:["); + } + let response = r.data.choices[0].text; convo += (response + '\n'); diff --git a/commands/premium/reminders.js b/commands/premium/reminders.js index c5318b0..bf698fe 100644 --- a/commands/premium/reminders.js +++ b/commands/premium/reminders.js @@ -50,9 +50,9 @@ function postEmbd(bot, desc, interaction, page, isGuild, id, refered) { row.addComponents(prevbtn, nextbtn); if (page > 0 || refered) { - interaction.update({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [newEmbed], components: [row] }); + interaction.update({ content: '_Note: To see a full list of reminder stats visit https://selmerbot.com _', embeds: [newEmbed], components: [row] }); } else { - interaction.reply({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [newEmbed], components: [row] }); + interaction.reply({ content: '_Note: To see a full list of reminder stats visit https://selmerbot.com _', embeds: [newEmbed], components: [row] }); } } catch (err) { console.log(err); diff --git a/commands/premium/stripe.js b/commands/premium/stripe.js index e5e6088..5491948 100644 --- a/commands/premium/stripe.js +++ b/commands/premium/stripe.js @@ -180,11 +180,13 @@ function handleInp(bot, interaction) { module.exports = { - name: 'premium', - description: 'everything payment', - execute(interaction, Discord, Client, bot) { - handleInp(bot, interaction); - }, handleInp, createSubscriptionManual, - options: [{name: 'input', description: 'What do you want to do?', type: Constants.ApplicationCommandOptionTypes.STRING, required: true, choices: [{name: 'help', value: 'help'}, {name: 'buy', value: 'buy'}, {name: 'manage', value: 'manage'}]}], - isDM: true + name: 'premium', + description: 'everything payment', + execute(interaction, Discord, Client, bot) { + handleInp(bot, interaction); + }, handleInp, createSubscriptionManual, + options: [ + {name: 'option', description: 'What do you want to do?', type: Constants.ApplicationCommandOptionTypes.STRING, required: true, choices: [{name: 'help', value: 'help'}, {name: 'buy', value: 'buy'}, {name: 'manage', value: 'manage'}]} + ], + isDm: true } \ No newline at end of file diff --git a/index.html b/index.html index 4f112e7..4f6ba40 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@
- +
diff --git a/main.js b/main.js index aa68c8e..896229d 100644 --- a/main.js +++ b/main.js @@ -52,7 +52,7 @@ if (process.env.token != undefined) { StripeAPIKey = require('./config.json').StripeAPIKey; youtubeAPIKey = require('./config.json').youtubeAPIKey; - IDM = true; + IDM = token.startsWith("OTI2NT"); } //#endregion @@ -121,12 +121,14 @@ process.on("SIGTERM", (signal) => { console.log(`Process ${process.pid} received a SIGTERM signal`); backupLists(bot, IDM); // process.exit(0); + bot.user.setStatus('invisible'); }); process.on("SIGINT", (signal) => { console.log(`Process ${process.pid} has been interrupted`); backupLists(bot, IDM); // process.exit(0); + bot.user.setStatus('invisible'); }); process.on('uncaughtException', (signal) => { @@ -140,6 +142,10 @@ process.on('uncaughtException', (signal) => { return; } + console.log(signal); + + if (bot.inDebugMode) { return; } + const guild = bot.guilds.cache.get(bot.home_server); const owner = guild.members.cache.get(guild.ownerId); preverr = signal.stack.toString(); @@ -150,6 +156,7 @@ process.on('uncaughtException', (signal) => { errmsg = msg; preverr = signal.stack.toString(); // exit(12); + bot.user.setStatus('dnd'); }); }); }); @@ -183,6 +190,7 @@ 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"); const { STATE } = require('./commands/db/econ.js'); +const replies = require('./commands/Selmer Specific/replies.js'); bot.commands.set('econ', temp_command); temp_command = require('./commands/games/game.js'); bot.commands.set('game', temp_command); @@ -207,6 +215,8 @@ var botIsReady = bot.inDebugMode; bot.on('ready', async () => { const startTime = new Date().getTime(); + bot.user.setPresence({ activities: [{ name: 'Booting up, please hold!', type: "PLAYING" }], status: 'idle' }); + registerCommands(bot).then(() => { //Make then copy the shop bot.mongoconnection.then(client => { @@ -216,9 +226,6 @@ bot.on('ready', async () => { items = [...itemstemp]; }); - - - bot.user.setStatus('online'); }); //Note the xp numbers are a little wonky on levels 6, 8 and 13 (why though?) @@ -230,7 +237,7 @@ bot.on('ready', async () => { } - //Reaction map area + bot.user.setPresence({ activities: [{ name: '/help', type: 'PLAYING' }], status: 'online' }); if (!bot.inDebugMode) { console.log('SLEEMER BOT ONLINE!!!!! OH MY GOD OH MY GOD!!!'); } else { @@ -322,7 +329,7 @@ bot.on("guildCreate", guild => { bot.mongoconnection.then(client => { 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, 'col': "#FFFFFF"}, {_id: 'LOG', 'keepLogs': false, 'logchannel': null, 'severity': 0}, {_id: 'announcement', channel: null, role: null}, {_id: 'roles', commands: ["Selmer Bot Commands"], announcements: "Selmer Bot Calendar"}]); }); }); @@ -390,22 +397,22 @@ bot.on('guildMemberAdd', async (member) => { bot.mongoconnection.then(client => { const dbo = client.db(member.guild.id).collection('SETUP'); - dbo.find({_id: 'WELCOME'}).toArray(async (err, docs) => { - if (!docs) { return; } + dbo.findOne({_id: 'WELCOME'}).then(async (doc) => { + if (!doc) { return; } var welcomechannel; - if (docs[0].welcomechannel == null) { + if (doc.welcomechannel == null) { welcomechannel = guild.channels.cache.find(channel => channel.name.toLowerCase() === 'welcome'); } else { - welcomechannel = guild.channels.cache.get(docs[0].welcomechannel) + welcomechannel = guild.channels.cache.get(doc.welcomechannel) } if (welcomechannel == null) { return; // console.log('No welcome channel detected'); } - await welcome(member, welcomechannel, docs[0].welcomemessage, docs[0].welcomebanner, (docs[0].welcometextcolor) ? docs[0].welcometextcolor : "#FFFFFF"); - }) + await welcome(member, welcomechannel, doc.welcomemessage, doc.welcomebanner, (doc.welcometextcolor) ? doc.welcometextcolor : "#FFFFFF"); + }); }) }); @@ -427,8 +434,16 @@ bot.on('messageCreate', (message) => { //Special case, testing server (still need the emojis and error logging) if (!bot.inDebugMode && message.guild.id == bot.home_server) { return; } + if (message.mentions.has(bot.user.id)) { + if (message.content == `<@${bot.user.id}>`) { + return message.reply("What?"); + } else { + return replies(bot, message); + } + } + //Check if the prefix exists - if (message.author.bot) { return } + if (message.author.bot) { return; } if (message.content.startsWith(prefix)) { //Game section (too complicated to move to Slash Commands) diff --git a/package-lock.json b/package-lock.json index d7b1186..93fbc16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "mal-scraper": "^2.11.4", "mongoose": "^6.3.2", "mysql": "^2.18.1", + "node-fetch": "^2.6.7", "node.js": "^0.0.1-security", "npm": "^8.13.2", "openai": "^3.0.0", @@ -54,6 +55,9 @@ "youtube-mp3-downloader": "^0.7.10", "ytdl-core": "^4.11.0", "ytdl-core-discord": "^1.3.1" + }, + "devDependencies": { + "@types/node-fetch": "^2.6.2" } }, "node_modules/@alpacahq/alpaca-trade-api": { diff --git a/package.json b/package.json index e060569..ca0f088 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "mal-scraper": "^2.11.4", "mongoose": "^6.3.2", "mysql": "^2.18.1", + "node-fetch": "^2.6.7", "node.js": "^0.0.1-security", "npm": "^8.13.2", "openai": "^3.0.0", @@ -62,5 +63,8 @@ "bugs": { "url": "https://github.com/ION606/selmerBot/issues" }, - "homepage": "https://github.com/ION606/selmerBot#readme" + "homepage": "https://github.com/ION606/selmerBot#readme", + "devDependencies": { + "@types/node-fetch": "^2.6.2" + } }