giorgi-o / SkinPeek

Awesome Valorant Discord bot to see your daily shop, night market, battlepass progression, and much more
GNU General Public License v3.0
217 stars 91 forks source link

Add account switching, update user json format, add sharding support #41

Closed giorgi-o closed 2 years ago

giorgi-o commented 2 years ago

Overall, quite a major update, with many features long overdue.

Account switching

Users can now be logged into multiple accounts on the bot, and switch between accounts without having to log in each time. When they /login, instead of replacing their current account, it will add another account to the account switcher. They can then switch accounts using /account and see all their accounts using /accounts. They can also log out and delete one of the accounts using /forget 3 to delete their 3rd account, for example.

Update user JSON format

Currently, the bot stores the data for all users in one giant users.json file, which works fine for small user bases, but now that the bot is being used in thousands of servers, it's causing a few problems, especially considering that the whole json file is being rewritten synchronously every time a change to a user is being made. The bot has been rewritten to store each user's data in a separate JSON file. I don't think I need to explain how much better this is performance-wise, and it also leads way for...

Sharding support

The bot has been using internal sharding until now, which is fine. although not optimal and definitely not scalable past 3-4k servers without using an absurd amount of RAM. TLDR, sharding is basically spawning several "mini-bots" and having each one handle ~1000 servers each. Since each bot is its own separate process, it should make resource management much easier. To use sharding, run node sharding.js instead of SkinPeek.js, although it doesn't really make sense to do so until 2k servers at least.

What's left to do

Most of these should be implemented by now, although there are a few things left to iron out before merging into main:

Those should be the main things to fix.

It is not recommended you use this branch in production just yet, although if you really want to, please backup all your stuff. If the bot corrupts it all, don't blame me.

Welp, I'm going to stop procrastinating and actually start implementing these things.

warriorzz commented 2 years ago

wow.

Seems good, but I have to add two comments: First of all, why don't we replace the json files with a database? I don't have much experience with relational databases, but I would suggest PostgreSQL. Secondly, if we already update how users are stored, we may think about #31. I'm not keen on merging, rather making the decision to close the pr (as there is no activity and this feature is nice) and implement it yourself.

What do you think about this?

giorgi-o commented 2 years ago

Thanks for the comments!

Using a database was actually my first thought as to how to solve the users.json issue. I don't know much about databases either, but all the ones I found require you to have a separate database.exe program running alongside the bot, which is not a bad thing in itself, although it does add an extra step to installing and starting up the bot. Having one file per user also works fine, with the upside that I can reuse at least some of the user storage code, and it makes it easy for whoever is hosting the bot to go into the data files and fix issues or edit them if they need to.

About #31, I think you're right about closing the pr, as the code is most definitely outdated and the pr is inactive anyways. I like the feature, so I'll most likely reimplement it myself at some point.

giorgi-o commented 2 years ago

Branch should be in final stages of testing. All features have been implemented, once I'm sure the branch is somewhat bug-free I'll merge to main.