From f77a4e4147902937a1221134ea0c16754bf0b078 Mon Sep 17 00:00:00 2001 From: ION606 Date: Wed, 1 Jun 2022 20:38:39 +0300 Subject: [PATCH] Worked on the 'game' command and added the 'meme' command --- .gitignore | 7 +- commands/admin/colorgen.js | 15 +++ commands/db/battle.js | 47 ++++++-- commands/db/external_game_functions.js | 1 + commands/db/game.js | 10 +- commands/misc/meme.js | 21 ++++ main.js | 6 +- package-lock.json | 147 +++++++++++++++++++++++++ package.json | 1 + 9 files changed, 237 insertions(+), 18 deletions(-) create mode 100644 commands/admin/colorgen.js create mode 100644 commands/misc/meme.js diff --git a/.gitignore b/.gitignore index 4901c3a..61100d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ node_modules config.json -.env -.sqlite +*.env +*.sqlite +*.txt +!spec/LevelsXP.txt database.sqlite temp.js -INTERACTION.txt \ No newline at end of file diff --git a/commands/admin/colorgen.js b/commands/admin/colorgen.js new file mode 100644 index 0000000..aae93d6 --- /dev/null +++ b/commands/admin/colorgen.js @@ -0,0 +1,15 @@ +function randomHexColor() { + var letters = "0123456789ABCDEF"; + + // html color code starts with # + var randomcol = '#'; + + // generating 6 times as HTML color code consist + // of 6 letter or digits + for (var i = 0; i < 6; i++) + randomcol += letters[(Math.floor(Math.random() * 16))]; + + return randomcol; +} + +module.exports = { randomHexColor } \ No newline at end of file diff --git a/commands/db/battle.js b/commands/db/battle.js index 37a986f..9cea7f0 100644 --- a/commands/db/battle.js +++ b/commands/db/battle.js @@ -1,6 +1,8 @@ //@ts-check +const { MessageActionRow, MessageButton, MessageSelectMenu } = require('discord.js'); const { STATE } = require('./econ'); const { winGame } = require('./external_game_functions.js'); +const { changeTurn } = require('../turnManager.js'); /** @@ -17,7 +19,6 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) { const doc = docs[0]; const all_weapons = doc.equipped.weapons; - console.log(all_weapons); const weapon = all_weapons.main; var dmg = 0; @@ -45,7 +46,7 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite if (new_hp <= 0) { winGame(client, bot, client.db(user_dbo.s.namespace.db), user_dbo, xp_collection, interaction.message); } else { - other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp }}); //THIS DOES NOT WORK (OVERWRITES HPMP MAP WITH ONE VALUE) + other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp }}); } }); @@ -54,16 +55,46 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite //Check for a "special" animation - + //Change turns + changeTurn(client, bot, interaction); } /** * Called by "item" */ -function heal(user_dbo, bot, thread, command, mongouri, items) { - +async function heal(interaction, user_dbo, bot, thread, command, mongouri, items) { + if (interaction.message.content.toLowerCase().indexOf('Which item would you like to use?') != -1) { + // The person picked out an item + } + //Get the 'healing' items (stored in "{item}: num" format) + user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) { + const doc = docs[0]; + const rawitems = doc.equipped.items; + if (JSON.stringify(rawitems) == '{}') { return thread.send("You don't have any items!"); } + const items = rawitems.filter(function(f) { return (f.sect.toLowerCase() == 'healing') }); + //Find something to heal with + const row = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId(`${interaction.user.id}|heal`) + .setPlaceholder('Nothing selected') + .addOptions([ + { + label: 'Select me', + description: 'This is a description', + value: 'first_option', + }, + { + label: 'You can select me too', + description: 'This is also a description', + value: 'second_option', + }, + ]), + ); + await interaction.reply({ content: 'Pong!', components: [row] }); + }); } @@ -88,7 +119,6 @@ function cast() { function postActionBar(thread, user_dbo) { - const { MessageActionRow, MessageButton } = require('discord.js'); const row = new MessageActionRow() .addComponents( new MessageButton() @@ -119,14 +149,13 @@ function handle(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite return postActionBar(thread, user_dbo); } else if (command == 'attack') { attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction); + postActionBar(thread, other_dbo); } else if (command == 'items') { item(); } else if (command == 'heal') { - heal(); + heal(interaction, user_dbo, bot, thread, command, mongouri, items); } - //Post the action bar for the next person's turn - postActionBar(thread, other_dbo); // initiate(user_dbo, other_dbo, command, message); } diff --git a/commands/db/external_game_functions.js b/commands/db/external_game_functions.js index 9cb0d44..869d57f 100644 --- a/commands/db/external_game_functions.js +++ b/commands/db/external_game_functions.js @@ -1,5 +1,6 @@ //@ts-check const { addxp, STATE, BASE } = require("./econ.js"); +const turnManger = require('../turnManager.js'); //#region game lose/win diff --git a/commands/db/game.js b/commands/db/game.js index 29266c2..c20413e 100644 --- a/commands/db/game.js +++ b/commands/db/game.js @@ -119,16 +119,22 @@ function acceptIsValid(bot, other_discord, message, msg, tag_len) { function hpmp(message, command, dbo) { // throw 'THIS HAS NOT BEEN UPDATED WITH THE MOST RECENT VERSION OF THE MONGODB STRUCTURE!'; if (command == 'hp') { - dbo.find({"hp": {$exists: true}}).toArray(function(err, doc) { + dbo.find({"hpmp": {$exists: true}}).toArray(function(err, doc) { return message.reply(`You have ${String(doc[0].hpmp.hp)} hp left!`); }); } else if (command == 'mp') { - dbo.find({"mp": {$exists: true}}).toArray(function(err, doc) { + dbo.find({"hpmp": {$exists: true}}).toArray(function(err, doc) { return message.reply(`You have ${String(doc[0].hpmp.hp)} mp left!`); }); } } + +function equip(client, message, command, dbo, bot) { + //Check if the user is already in a game + +} + //#endregion diff --git a/commands/misc/meme.js b/commands/misc/meme.js new file mode 100644 index 0000000..46bc99f --- /dev/null +++ b/commands/misc/meme.js @@ -0,0 +1,21 @@ +const memes = require("random-memes"); +const { randomHexColor } = require('../admin/colorgen.js'); + + +module.exports = { + name: 'meme', + description: 'Selmer Bot will post a random meme from reddit', + async execute(message, args, Discord, Client, bot) { + memes.random().then(meme => { + + const newEmbed = new Discord.MessageEmbed() + .setColor(randomHexColor()) + .setTitle(meme.caption) + // .setURL(meme.image) + .setDescription(`category: ${meme.category}`) + .setImage(meme.image); + + message.channel.send({ embeds: [newEmbed] }); + }) + } +} \ No newline at end of file diff --git a/main.js b/main.js index 215671f..de3922b 100644 --- a/main.js +++ b/main.js @@ -147,7 +147,7 @@ bot.on('interactionCreate', async interaction => { 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(); @@ -158,10 +158,8 @@ bot.on('interactionCreate', async interaction => { bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection); } - turnManager.changeTurn(client, bot, interaction); - //remove the old interation message - interaction.message.delete(); + // interaction.message.delete(); interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`); } else { diff --git a/package-lock.json b/package-lock.json index c6073cc..288edb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "mysql": "^2.18.1", "node.js": "^0.0.1-security", "play-dl": "^1.9.4", + "random-memes": "^3.1.0", "sequelize": "^6.19.0", "sqlite3": "^5.0.3", "sudo": "^1.0.3", @@ -653,6 +654,20 @@ "node": ">= 10" } }, + "node_modules/canvas": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.9.1.tgz", + "integrity": "sha512-vSQti1uG/2gjv3x6QLOZw7TctfufaerTWbVe+NSduHxxLGB+qf3kFgQ6n66DSnuoINtVUjrLLIK2R+lxrBG07A==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.0", + "nan": "^2.15.0", + "simple-get": "^3.0.3" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -811,6 +826,17 @@ } } }, + "node_modules/decompress-response": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz", + "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==", + "dependencies": { + "mimic-response": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -1721,6 +1747,17 @@ "node": ">= 0.6" } }, + "node_modules/mimic-response": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", + "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/miniget": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.2.tgz", @@ -1953,6 +1990,11 @@ "node": ">= 0.6" } }, + "node_modules/nan": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.16.0.tgz", + "integrity": "sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==" + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -2292,6 +2334,19 @@ "node": ">=0.6" } }, + "node_modules/random-memes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/random-memes/-/random-memes-3.1.0.tgz", + "integrity": "sha512-HmtVczuI7QZvfuXwmG090md5+UVGNKxf2pjbNwxoFWw4y9/Abna3TvTyNY2BotSRdXi5QNmb2q0aYvvah84FhQ==", + "dependencies": { + "canvas": "^2.8.0", + "node-fetch": "^2.6.1", + "user": "*" + }, + "bin": { + "random-memes": "src/index.js" + } + }, "node_modules/read": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", @@ -2543,6 +2598,35 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, + "node_modules/simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/simple-get": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz", + "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==", + "dependencies": { + "decompress-response": "^4.2.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -2837,6 +2921,11 @@ "punycode": "^2.1.0" } }, + "node_modules/user": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/user/-/user-0.0.0.tgz", + "integrity": "sha1-8n8bI/xRHyqO+kDbVc+6Ejgk4Co=" + }, "node_modules/utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", @@ -3596,6 +3685,16 @@ "unique-filename": "^1.1.1" } }, + "canvas": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.9.1.tgz", + "integrity": "sha512-vSQti1uG/2gjv3x6QLOZw7TctfufaerTWbVe+NSduHxxLGB+qf3kFgQ6n66DSnuoINtVUjrLLIK2R+lxrBG07A==", + "requires": { + "@mapbox/node-pre-gyp": "^1.0.0", + "nan": "^2.15.0", + "simple-get": "^3.0.3" + } + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -3710,6 +3809,14 @@ "ms": "2.1.2" } }, + "decompress-response": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz", + "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==", + "requires": { + "mimic-response": "^2.0.0" + } + }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -4405,6 +4512,11 @@ "mime-db": "1.52.0" } }, + "mimic-response": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", + "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==" + }, "miniget": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.2.tgz", @@ -4577,6 +4689,11 @@ "sqlstring": "2.3.1" } }, + "nan": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.16.0.tgz", + "integrity": "sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==" + }, "negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -4846,6 +4963,16 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==" }, + "random-memes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/random-memes/-/random-memes-3.1.0.tgz", + "integrity": "sha512-HmtVczuI7QZvfuXwmG090md5+UVGNKxf2pjbNwxoFWw4y9/Abna3TvTyNY2BotSRdXi5QNmb2q0aYvvah84FhQ==", + "requires": { + "canvas": "^2.8.0", + "node-fetch": "^2.6.1", + "user": "*" + } + }, "read": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", @@ -5029,6 +5156,21 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, + "simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==" + }, + "simple-get": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz", + "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==", + "requires": { + "decompress-response": "^4.2.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, "smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -5268,6 +5410,11 @@ "punycode": "^2.1.0" } }, + "user": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/user/-/user-0.0.0.tgz", + "integrity": "sha1-8n8bI/xRHyqO+kDbVc+6Ejgk4Co=" + }, "utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", diff --git a/package.json b/package.json index e9e5e37..45487fa 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "mysql": "^2.18.1", "node.js": "^0.0.1-security", "play-dl": "^1.9.4", + "random-memes": "^3.1.0", "sequelize": "^6.19.0", "sqlite3": "^5.0.3", "sudo": "^1.0.3",