Handle off-topic channel names that are invalid for servers in Server Discovery#2520
Handle off-topic channel names that are invalid for servers in Server Discovery#2520TizzySaurus wants to merge 17 commits into
Conversation
RohanJnr
left a comment
There was a problem hiding this comment.
Tested and works fine. Gj
|
Also, the |
That seems unrelated to this work, so should probably go in a separate PR? |
Ye sure, I'll open an issue for that later |
| new_channel_names: list = await self.bot.api_client.get( | ||
| "bot/off-topic-channel-names", params={"random_items": num_names_to_fetch} | ||
| ) | ||
| if (num_fetched := len(new_channel_names)) < num_names_to_fetch: |
There was a problem hiding this comment.
IS this even possible ? We have a ton of channel names and we only rename 3.
There was a problem hiding this comment.
It is strictly possible, however unlikely, so figured it should be accounted for - especially since the handling is relatively simple.
There was a problem hiding this comment.
The handle for this has changed with the rewrite, but is still there here. Also figured it made more sense to send a message to mod_meta than a log.warn, so updated to reflect that.
There was a problem hiding this comment.
I agree with keeping the handle since it could save some of my brain cells when, say, I'm running my own instance of the bot in a test server.
| failed_renames = defaultdict(list) | ||
| successfully_renamed = set() | ||
| for attempt in range(MAX_RENAME_ATTEMPTS): | ||
| # Get the necessary amount of new channel names |
There was a problem hiding this comment.
I don't think that all these comments are necessary, comments should exist to document things that don't jump straight to the eye.
There was a problem hiding this comment.
That's what I'm saying, that the code can be understood by simply reading it, as the logic is kinda straightforward.
I personally don't think it's complex, we'll see what others have to say about it.
There was a problem hiding this comment.
Yeah, in hindsight I agree -- these comments were removed as part of the rewrite.
| channels = [await get_or_fetch_channel(channel_id) for channel_id in CHANNELS] | ||
| failed_renames = defaultdict(list) | ||
| successfully_renamed = set() | ||
| for attempt in range(MAX_RENAME_ATTEMPTS): |
There was a problem hiding this comment.
I think the approach can be enhanced a bit.
We can fetch 3 names (number of attempts) for each channel.
We iterate over each channel, and try to rename it three times, then exit, that way we can increase the chance of a successful rename OP.
number_of_names_to_fetch = MAX_ATTEMPS * len(CHANNELS)
channels = [get_or_fetch_channel(channel) for channel in CHANNELS]
names = iter(api_client.fetch_names(params={"random_items": number_of_names_to_fetch}))
renamed = set()
failed = set()
for channel in channels:
attempt = 0
while attempt < MAX_ATTEMPS:
attempt += 1
try:
old_name = channel.name
name = next(names)
channel.update(name=name)
renamed.add(channel.id)
break
except:
# Catch your code here & deactivate the name
# Reraise if not the right exception
failed.add(f"- {name}\n") # Leverage the new markdown support to dsplay as a bullet list
...
# Simplify the handling of the failed renames.
if failed:
unchanged = [channel.name for channel in channels if channel.id not in renamed]
message = f"Couldn't rename the following off-topic channels: {', '.join(unchanged)}" \
f"The following off-topic names were deactivated:\n{failed}", There was a problem hiding this comment.
Rewritten in 2f738ad (have made changes since, so see the "Files Changed" for modern version of the logic).
Currently untested, but lmk what you think :)
|
Closing in favor of recreating within a new PR. |
Related Issues
Closes #2282
Closes #2500
What
This PR adds re-roll logic for when attempting to rename an off-topic channel to a name that's not allowed for servers in Server Discovery (such as
ot0-welcome-and-fuck-you).It will attempt to reroll a maximum of
MAX_RENAME_ATTEMPTSper off-topic channel, and will send a message detailing any failed renames for a given off-topic channel to the internal mod-meta channel.The code also deactivates names that are invalid, triggering a
log.info, and adds logic for handling when the name pool isn't big enough (which triggers alog.warn).Testing
As for testing, I found that the following works:
...and produces the following example message in the mod-meta channel:

To forcefully run the coroutine you can use the
int evalcommand, with the following code: