-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The code is bad #2
Comments
that's just one issue, why tf is there a dm all command, on top of being API abusive, ANYONE CAN USE THIS |
you should not be doing so much code in on_ready, as it may get called multiple times in a bot's runtime, should create an async task instead |
I just found this repository and have found numerous rookie mistakes. You're creating a new table every single time the client joins a new guild which if you learn anything about Database's you know this is just a bad idea in general. There's general bad things going on in the code itself as well such as checking the equality of a argument to SELECT * FROM {member.display_name}; That is a very niché case but it's an example of a terrible statement with a format string in Python. |
Thank you for letting me know this, I didn't realise about the tables, I'd seen that the number of tables didn't matter. I will add the guild_id as another key and have every entry in one table, would that be better? For only having one connection at a time, that makes a lot of sense now, I'd thought that because I was closing the database it was fine, however, I completely overlooked the fact that if two people use the command at the same time when updating, it could cause problems. So, should I simply connect at the start of the program, and then close it when the program finishes? How would I make sure it closed as the code would not finish if I simply stopped it from running? Thanks. |
It was made for a youtube tutorial, why would I have a bunch of random commands together in one bot like this? This bot is not a real bot, its just a collection of code from my series. |
First of all, thanks for the criticism, not sure you wrote it in the nicest or most constructive way but I will take it. The tables issue has already been brought up and to be honest, it just made sense to me to have the database split into a table for each guild as it removed the need for another field for the guild id, please could you tell me why it is a bad thing, or is it the dynamic creation of them? |
Thank you, I've managed to forget how the bot will disconnect and reconnect overtime. Should this be a background task? Or how would I go about this as I only want to do it when the bot starts but if I do it before the on_ready event fires, it won't work as bot.guilds won't be ready etc? |
Once I have received your feedback I will rewrite parts. |
yes, most of these solutions are good, regarding how to close it when the program is done, you can subclass the |
something such as a |
Yeah pretty much everything Pika said, you should have a single table for guilds in your db e.g. named called Columns: Unsure if you're aware of constraints etc |
Just a general comment involving table schemas, while you have a limited number of columns and tables, you do however have a pretty much unlimited amount of rows, which you should take advantage of. |
Regarding injections, even if its not possible to become malicious, it's still better practice to use the library sanitization. It should also be noted that as this is a tutorial, people will read this and use it for other projects, which may have problems with injections. |
Slight another comment, you have
inside the client version, shouldn't this be instead of bot? unless I'm misunderstanding |
Okay, thank you, and that will work if the program somehow crashed? |
Thought so, I've used the event loop before in other programs, thanks again. |
Thank you, I am aware, in my case, it would be something like this for the rows though right as I would need to be searching for both guild and user id as they would appear multiple times in the table? Or, would I concatenate them and use that as the primary key, like this, so it would be a string that I would search for? I believe the later option would work better as then I'm not searching for two ids? |
Yes, I completely agree, thanks, I made sure to mention that but will most likely be remaking the video and updating it in response to this issue that you created. In regards to the checking against None, I've just noticed that I used '==' to compare against it once, which is my mistake and I've used 'is' to compare them, for a long time, for your exact reason as I've researched this is the past. I was confused at what kal-byte mentioned because I know that using '==' is wrong but I presumed that he was referencing me using 'is', I will correct that, thank you. |
Yes that's an oversight on my part, I used the replace function to replace every instance of 'bot' with 'client' and clearly missed that comment. I will update that, thanks. |
Well for separate users you may want to create a separate table for this maybe the primary key just being a SERIAL? and then the guild id can reference the guild in the guilds table with 2 other columns them being user_id and their current xp |
its possible that guild_id+user_id would work, however this is less clean. |
if something such as the host crashing happens, it will not work, but not closing the connection shouldn't be a big problem anyways. |
I'm not sure, what you mean by SERIAL, please could you clarify? |
Okay, thanks, so I should opt for having the two keys, guild_id and user_id? |
Yeah, that makes sense, thanks again. |
yeah I would think this is more clear, especially since this is for a tutorial |
SERIAL is basically auto-increment so once you insert a row it'll go up by 1
So say you were to delete the 3rd one this will be the end result:
Note how 4 doesn't change, if you entered another row it'll be 5 rather than 3 or another number. |
Got it, thanks. |
Sounds good, I'll redo it all, thank you for your constructive criticism. |
Creating a table for every guild is a horrible horrible idea, on top of the fact that you only should have one aiosqlite connection at a time.
The text was updated successfully, but these errors were encountered: