jlsigmon / IndustrialIllusionsBot

A discord bot for collecting Yugioh cards
1 stars 0 forks source link

Migration #2

Open LVricella opened 1 year ago

LVricella commented 1 year ago

How hard would it be to migrate the message commands to / commands?

jlsigmon commented 1 year ago

I personally haven't looked too much into the api for using getting it to work with / commands since that came after I built the bot. From looking at this website, it looks like it is mainly just reformatting each command js file and then editing the index file a bit to use the new slash command method which should make the index file way smaller in terms of # of lines https://discordjs.guide/creating-your-bot/command-handling.html#executing-commands.

Doesn't seem too difficult but it would be time consuming. Also I am unsure if there would be a need to upgrade the version of discord.js to accomplish this. I could take a look at it tomorrow.

LVricella commented 1 year ago

Thanks! That would be great

jlsigmon commented 1 year ago

Definitely is something thats going to take a little bit of time. I'm going to see if I can get most of it done over the weekend. I will also likely try to clean up the index file a bit.

LVricella commented 1 year ago

Thank you for taking time to look at it, most appreciated!

LVricella commented 1 year ago

Hey, have you had any chance to take a look at this?

jlsigmon commented 1 year ago

I haven't been able to work on this yet. I started working recently and its been harder to find time to look at personal coding projects.

jlsigmon commented 1 year ago

I have been slowly making some progress and getting an understanding for how it works. I have a couple commands working now. Will keep you posted as I keep making progress.

LVricella commented 1 year ago

Thanks, your effort is much appreciated

LVricella commented 1 year ago

Hey @jlsigmon - would you be able to guide me on how can I set a maximum for the users collection? For example, I want every user to be able to have a maximum of 32 unique cards (that means you can have 32 uniques but allowing you to have those repeated). I would need the pack opening command to read the collection and if the collection is already full to return an error message stating the collection is full and not allowing the user to open the pack. So, in theory I know how I want it, but I don't know how to get it done. Thanks!

jlsigmon commented 1 year ago

Sure! That is fairly easy to do. You would probably end up needing two checks one before opening and one while opening incase the newly opened item would put them over whatever limit you set but pretty much it would look somewhat similar to the lines 185 through 202 in the packType files.

con.query(SELECT * FROM collection WHERE userId = '${msg.author.id}' AND serverId = "${msg.guild.id}" AND cardName = ? AND cardRarity = "${newRarity[i]}"`, [newCard[i]], (err, rows) => { if (err) throw err;

                        var sql;

                        if (rows.length > 0) {
                            var total = rows[0].cardNum;
                            totalAdd = numNew[i];
                            sql = `UPDATE collection SET cardNum = ${total + totalAdd} where userId = "${msg.author.id}" AND serverId = "${msg.guild.id}" AND cardName = ? AND cardRarity = "${newRarity[i]}"`;
                            con.query(sql, [newCard[i]], console.log);
                        } else {
                            let sql2;
                            totalAdd = numNew[i];
                            sql2 = `INSERT INTO collection (userId, serverId, cardName, cardRarity, cardNum) VALUES ('${msg.author.id}', "${msg.guild.id}", ?, "${newRarity[i]}", ${totalAdd})`;
                            con.query(sql2, [newCard[i]], console.log);
                        }
                    })`

For adding a check at the start of the pack opening command you would do something like this for a limit of 32:

con.query(SELECT * FROM collection WHERE userId = '${msg.author.id}' AND serverId = "${msg.guild.id}", (err, rows) => { if (err) throw err;

                        var sql;

                        if (rows.length >= 32) {
                            msg.reply("Sorry but you have reached the limit to the number of cards you can have in your collection!")
                        } else {
                            //this means they have less than 32 cards and you can proceed with the normal pack opening code
                        }
                    })`

And then if you wanted it to be a dynamic number where how large their collection could be is tied to a role they to the server or something you could just make the 32 a variable instead and do a check for the users role and then set the variable based on that.

LVricella commented 1 year ago

Thanks! I'm trying to apply it and it lets the user know the collection is full, but it isn't preventing the pack from being opened. The card is added to the collection and the coins are removed. Surely I'm doing something wrong.