Implement !tunnel command#3516
Conversation
5b4d35e to
9d2c86c
Compare
…east active off-topic channel selection)
9d2c86c to
3bf675d
Compare
|
I do have a couple of questions though, first, so currently I have made it so that only Another thing is that if I change the command method signature to use Then also, if I use the Should there be checks for whether the given channel is a DM channel or some such? Currently it just seems to treat it as incorrect channel ID (probably because it's not a Similarly, what to do about Is there a simple way to do overloads for this command? So that with one argument it's Any shortcuts/convenience functions I should use for say permission checks from the existing code base? Does this need unit or integration tests? |
jb3
left a comment
There was a problem hiding this comment.
Nice initial implementation, a few feedback comments. Will address your other comments in a second.
Sounds fine — with the necessary cooldown added as mentioned so users cannot spam this in places we have less visibility.
This sounds weird, do you get the same if you try use
I wonder if using a https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.TextChannelConverter might help?
You can use a guild-only decorator to enforce this.
Same as above.
Not easily without doing most of the argument handling yourself. I was going to suggest that for this initial implementation though we ditch the source channel support. Especially since the user who did the tunneling isn't mentioned in the tunneling messages it seems ripe for abuse (e.g. someone spamming in bot commands with another source & dest). For now, let's keep things simple and just implement an optional destination channel.
You can if you want to (and if you remove the source stuff it should be easier), we do have some utilities for mocking Discord components here and it's not too hard to add new bits. |
|
Also, on the last point about abuse: can we include the user who tunneled on both the source and destination message (username is fine, doesn't need to be a mention), so that we can easily see any problems without having to look through message logs. |
wookie184
left a comment
There was a problem hiding this comment.
Thanks for working on this :)
Potential simplification:
- Get the channels in the
cog_loadand store them in in a list e.g.self.channels - replace
get_least_active_channel_idwithget_least_active_channelthat looks something likereturn min(self.channels, key=lambda c: thattimeutilthing(c.last_message_id) - Then the
channel_id_to_timestamplogic +on_messagearen't needed at all, and it's a bit simpler as you're passing the channel around instead of the channel id (don't need to fetch it).
| if not isinstance(channel, discord.TextChannel): | ||
| raise AssertionError | ||
|
|
||
| last_message = channel.last_message |
There was a problem hiding this comment.
I don't think this will work. From what I can see the Discord API returns a last_message_id along with the channel, but discord.py requires the message to be in the cache for last_message to be populated. If the bot has just loaded, the message wont be in cache.
The easiest fix is probably to use channel.last_message_id directly with https://discordpy.readthedocs.io/en/latest/api.html#discord.utils.snowflake_time
…hannel.last_message docs' suggestion channel.last_message: "For a slightly more reliable method of fetching the last message, consider using either history or fetch_message with the last_message_id attribute."
…issing from the cache on load
…nce it doesn't appear to be super necessary here
Co-authored-by: Joe Banks <joe@jb3.dev>
… of .get (for typing purposes)
…nt permanent source_channel
…hor id (as a ping) in the message as well (to prevent/detect potential abuse)
Fixes #3512