-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Migrate all message utils from bot and sir-lancebot. #141
base: main
Are you sure you want to change the base?
Conversation
❌ Deploy Preview for bot-core failed.
|
I don’t think we should implement constants this way. How would someone test bot features which rely on these constants? To be clear, this is not your fault, nor something that can be fixed in this PR, as it requires serious work on how we approach constants in bot-core in general. Work that we have so far failed to do. When bot-core was first starting, this topic came up, and I fought to try and get what I think is the best compromise implemented, however I met great resistance. I’ll start with the facts:
From here, things shift from requirements/facts to possible solutions. My suggested implementation is as follows:
The largest pushback to this idea was from concerns that changing the constants would require two PRs, and to that I say: it's unavoidable. With our current approach, we have the constants hardcoded here, and coded into it's project which would require two PRs. If we pass constants to functions, we'd still have to change them in whichever project uses them. If we go with one of the other suggested ideas, which was to hardcode constant names into bot-core, and access them from the upstream project based on the names, that still requires two PRs, and makes bot-core a lot more fragile, and keeps the pointless repeition. If we use my suggested idea, you need to make two PRs, one to update the version in bot-core, and one to bump bot-core in the downstream project. |
I agree that hardcoding these constants is the least preferable way to handle it. I still don't like the suggestion though.
Yes, once. In this PR there is only one usage for these constants, and they could be easily passed as a I'd prefer bot-core to stay a generic library for bots. If we start tying it to specific projects I can only see it becoming cumbersome down the line. I'm also not sure how overriding those constants would work, but it sounds like it would be messier, and new contrib are already struggling with that. And if providing a constant as an argument is not viable in some situation? Then that might be where bot-core's limit is, assuming we can agree on the same vision for it. It solves a lot, but it doesn't have to solve everything. But for this specific PR again this can just be provided as a keyword arg. |
It is only one PR in some scenarios, but from my experience trying to migrate some of the utils, you'll still end up in a scenario having to change both. One example from here would be modifying the moderator role ID, and modifying the list of roles considered "mod roles" (like we did when we split the mod role in two). In the provided example, you can work around that by passing the set of IDs directly, and despite being a cumbersome and repetitive API, will work. This is not true for all things, as our utilities make assumptions about what is expected. I'd also like to point out that bot-core's setup would be very similar to python-discord/bot, and for most purposes we can do it with no changes required. The user will have a config file in the project directory they are working on, as we have now. That config file will contains the constants of bot-core (channels and roles and other URLs and IDs), and other project specific configuration. Or we could split the project configuration out. IMO this makes it even easier for contributors since you can just copy the same config into your different projects instead of setting up configs for each one. I also don't like the notion that this is a "generic bot library" when that has been something we decided against multiple times, with a lot of the things here already functioning in ways that are unique to our bots. |
I like Hassan's suggestion here. My understanding on roughly how it could work:
I'm not sure what particular case you're thinking of here. For something like
I don't see how it would be different to what we have on individual projects. If a util doesn't do what you want you change it so it does or use something else. Where do we override constants on other projects and why would we need to do it here?
What do you mean by "changing constants", like changing the value of a constant? If so why would that require two PRs? I don't think the values of constants should be stored on bot-core. |
I said in the previous comment I agree hardocoding is not a good solution, so I'm not sure what this is aimed at.
I'd like to understand what utils use such assumptions.
I'm really not sure about this. We have the bot config, the optional metricity config, and we're also considering another config for the automatic server creation tool. With another split, that's potentially 4 configs for a single project, it sounds terrible.
bot-core is based on common usage cases in our bots, so of course it's going to have things that are specific to our bots, but they can be easily used in any project which imports bot-core. I think keeping it clean of constants will help decide what is and isn't appropriate for this project. Otherwise bot-core can just be a dump of anything that is similar between the bots, and it will just help create situations where later we find out that the we moved a util away from bot A but now we need the util to work in a way that doesn't reconcile with how it was written into bot-core. I'm also not sure what we decided multiple times against since I'm not suggesting publishing bot-core on PyPI.
What I'm trying to say is that we will need to either
That's the whole suggestion though, storing the common constants in bot-core. |
Isn't this the whole purpose of bot-core (to remove duplicate code between the bots)? I personally would be for a Yes, this means 2 PRs when moving constants to bot-core (1 on bot-core and one on the repo it used to be on for migrating to bot-core imports), but I don't see this as a huge issue, and is already the case for all the utils etc. we have migrated in the past, so is no real difference to what we've been doing this whole time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further to this, before we can merge this, we should have a bot PR that implements this logic, so we can actually test the code.
…rs` and `allowed_roles` kwarg.
Yep! I'll work on a PR for both bot and lance migration to these utils. 👍 |
As the title says, with approval from @ChrisLovering in dev-contrib.
This migration does contain a few changes, as per the following:
Constants
Since some of bot's message utils used constants, which don't exist on botcore, these had to be changed as follows:
NEGATIVE_REPLIES
- defined as a constant at top of fileEmojis.trashcan
- hardcoded into thewait_for_deletion
parameterRoles.moderation_roles
- defined as a constant at top of fileSince it was decided we didn't want the
NEGATIVE_REPLIES
orMODERATION_ROLES
approach, but we don't know what we do want, I've instead just passed them in as arguments so that this can get merged (as per @mbaruh's suggestion).Typehints
Since botcore runs on 3.10 (along with both bots), I changed all the
Optional
andUnion
imports to use the new|
syntax (Optional[str]
->str | None
andUnion[str, int]
->str | int
etc.).Function Signatures
All the signatures remained the same, except for bot's
wait_for_deletion
, which now takes abot
parameter as the first argument.This is because it used
bot.instance.wait_for
, which is now simplybot.wait_for
.Other
bot.instance
changeSimilarly, the
reaction_check
util hasuser != bot.instance.user
to restrict reactions to users who weren't the bot.This has been changed to
not bot.user
instead, which is strictly different functionality but serves the same purpose.Duplicate Utils
The only duplicate util was the
sub_clyde
util. Both implementations were the exact same, so nothing has changed in terms of functionality.Imports
sir-lancebot had some
from discord import ...
imports, which have been changed to simply use thediscord
import, as well as somefrom discord.ext.commands import ...
imports, which have been changed to use thefrom discord.ext import commands
import.I also changed both bot's
from bot.log import get_logger
and sir-lancebot'simport logging
to usefrom botcore.utils.logging import get_logger
, and updated thelog
definition as such.