Skip to content

Relay all DMs sent to the bot to #dm_log#1041

Merged
kosayoda merged 18 commits into
masterfrom
dm_relay
Jul 15, 2020
Merged

Relay all DMs sent to the bot to #dm_log#1041
kosayoda merged 18 commits into
masterfrom
dm_relay

Conversation

@lemonsaurus
Copy link
Copy Markdown
Contributor

This PR adds a feature which will relay DMs sent to the bot through a simple webhook relay system. It also provides a mechanism for responding to these DMs, should you need to do so.

The mechanism for responding will by default respond to the last person who DMd the bot, but can optionally take a member parameter to reply to a specific member.

image

Refactoring Duck Pond and Python News

To do this in a DRY way, I first refactored the send_webhook helper used in Duck Pond into a generic util, which could be used for both Duck Pond and the DM Relay cog.

As it turns out, we had a similar mechanism in use over in the Python News handler as well, so I had to refactor that as well to use this util.

Fixing the DuckPond tests

Holy shit, DuckPond has ten million tests, and half of them broke when I made the first change. So I had to fix some of those broken tests.

Add the DMRelay cog

Next, we add a cog that will just relay anything that is a DM sent by a human to the right channel. The cog also adds the command to allow you to respond. Easy peasy.

Closes #667.

Leon Sandøy added 8 commits July 12, 2020 14:40
Some of the tests were failing because they were expecting send_webhook
to be a method of the DuckPond cog, other tests simply were no longer
applicable, and have been removed.

#667
This shouldn't be used as a replacement for ModMail, but I think it
makes sense to have the feature just in case #dm-log provides an
interesting use-case where responding as the bot makes sense.

It's a bit of a curiosity, and Ves hates it, but I included it anyway.

#667
@lemonsaurus lemonsaurus requested a review from a team as a code owner July 12, 2020 18:31
@lemonsaurus lemonsaurus requested review from dementati and tagptroll1 and removed request for a team July 12, 2020 18:31
@ghost ghost added the needs 2 approvals label Jul 12, 2020
Comment thread bot/cogs/dm_relay.py Outdated
Comment thread bot/cogs/python_news.py
Comment thread bot/utils/webhooks.py
Comment thread bot/cogs/dm_relay.py Outdated
Comment thread bot/cogs/dm_relay.py
@ghost ghost added s: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Jul 13, 2020
Comment thread bot/cogs/dm_relay.py Outdated
@MarkKoz MarkKoz added p: 3 - low Low Priority t: feature New feature or request labels Jul 13, 2020
@ghost ghost added needs 2 approvals and removed s: waiting for author Waiting for author to address a review or respond to a comment labels Jul 13, 2020
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing.

Comment thread bot/cogs/dm_relay.py
@ghost ghost added s: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Jul 13, 2020
Also now catches the exception if a user has disabled DMs, and adds a
red cross reaction.

#667
@ghost ghost added the needs 2 approvals label Jul 13, 2020
Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!
As it stands, moderators can !reply anywhere in the server. Is that something we want?

@ghost ghost added s: waiting for author Waiting for author to address a review or respond to a comment and removed needs 1 approval labels Jul 14, 2020
@lemonsaurus
Copy link
Copy Markdown
Contributor Author

lemonsaurus commented Jul 14, 2020

As it stands, moderators can !reply anywhere in the server. Is that something we want?

Hmm, good question. We might want to contain that in the #dm-log channel so that all the dm traffic (both in and out) is in one place. I'll make that change.

@Numerlor
Copy link
Copy Markdown
Contributor

Should the cog make some attempts to mitigate issues when the !reply command is used for the last user, but an another DM comes in while the invokation message is being sent and processed?

@lemonsaurus
Copy link
Copy Markdown
Contributor Author

Should the cog make some attempts to mitigate issues when the !reply command is used for the last user, but an another DM comes in while the invokation message is being sent and processed?

I did consider this, and I wonder how much of a problem it's really going to be.

How would you suggest we could go about mitigating this anyway?

@lemonsaurus
Copy link
Copy Markdown
Contributor Author

the easiest approach would be to just remove the whole last user feature altogether and always require a member to be specified. More technical approach would be some sort of locking mechanism, but I'm not really keen to complicate this. This feature is absolutely not meant to be used for anything serious, so it feels like even if the DM gets delivered to the wrong person, it shouldn't really do any damage.

@Numerlor
Copy link
Copy Markdown
Contributor

Perhaps some sort of a delay on the setting the user would be enough to give time for the person writing it to notice the change without influencing other things.
Are there any stats on how many dms the bot gets? If it's something relatively rare and the command is supposed to be used mostly for some shenanigans then the current approach ought to be fine. But if it's also supposed to be used sparingly then making the user a required argument shouldn't be that much of a problem for the people replying.

@lemonsaurus
Copy link
Copy Markdown
Contributor Author

Yeah, I'm leaning towards just simplifying and requiring the user to prevent this kind of race condition issue.

We don't have any such stats from what I'm aware. I'm curious myself. Maybe this PR should add stats for that, too.

If you're typing up a reply and the bot gets another DM while you're
typing, you might accidentally send your reply to the wrong person.

This could happen even if you're very attentive, because it might be a
matter of milliseconds. The complexity to prevent this isn't worth the
convenience of the feature, and it's nice to get rid of the caching as
well, so I've decided to just make .reply require a user for every
reply.

#1041
@ghost ghost added needs 1 approval and removed s: waiting for author Waiting for author to address a review or respond to a comment labels Jul 14, 2020
@lemonsaurus
Copy link
Copy Markdown
Contributor Author

oh shit, that last commit was supposed to be two commits, but anyway I've made the changes requested by @kosayoda and @Numerlor now:

  • It is no longer possible to use .reply outside the #dm-log channel.
  • .reply now requires a user to be specified for each call. This is to prevent situations where you would reply to the wrong person. It also has the added benefit of removing a bit of complexity (to do with caching)

Copy link
Copy Markdown
Contributor

@kosayoda kosayoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great now.

@ghost ghost removed the needs 1 approval label Jul 15, 2020
@kosayoda kosayoda merged commit caf5be2 into master Jul 15, 2020
@kosayoda kosayoda deleted the dm_relay branch July 15, 2020 03:50
lemonsaurus pushed a commit that referenced this pull request Jul 15, 2020
Without this, it is difficult to know precisely who the user that is
DMing us is, which might be useful to us.

#1041
lemonsaurus pushed a commit that referenced this pull request Jul 15, 2020
lemonsaurus pushed a commit that referenced this pull request Jul 15, 2020
When we're using the !reply command, using a regular UserConverter is
somewhat problematic. For example, if I wanted to send the message
"lemon loves you", then I'd try to write `!reply lemon loves you` -
however, the optional User converter would then try to convert `lemon`
into a User, which it would successfully do since there's like 60 lemons
on our server.

As a result, the message "loves you" would be sent to a user called
lemon.. god knows which one.

To solve this bit of ambiguity, I introduce a new converter which only
converts user mentions or user IDs into User, not strings that may be
intended as part of the message you are sending.

#1041
lemonsaurus pushed a commit that referenced this pull request Jul 15, 2020
lemonsaurus pushed a commit that referenced this pull request Jul 15, 2020
kwzrd pushed a commit that referenced this pull request Jul 16, 2020
Add upstream changes & resolve config conflicts introduced by #1041.

In the conflicting parts of the diff, this commit also re-sorts
constants which were added upstream to lexicographical order.

This does **not** re-sort all constants added upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: 3 - low Low Priority t: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relay all bot DM's to log channel

4 participants