-
Notifications
You must be signed in to change notification settings - Fork 26
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
Update help channel embed when channel is occupied #117
Conversation
https://discord.com/channels/508357248330760243/508357683506708514/821851432235433984 ^As @genchatypescript-community#69 points out, once a channel has been claimed, there's still a big 'ol embed just a little ways up that describes the channel as available -- which might contribute to help-channel sniping. This adds a new embed which marks the channel as occupied. It does not use it anywhere yet; that'll come soon.
Pull updateStatusEmbed out into a helper function while we're at it, used for changing the status from dormant to available, too. Occupied => dormant doesn't need to update the status since it always adds a new message. Maybe it doesn't need to when someone deletes their question, though..
It used to check against the available embed contents, but there's a new embed in town! We also need to check against the title now, because the occupied embed body changes depending on who claimed the channel.
Looks good! Can I see a screenshot of the updated embed? |
As soon as I get it running 😄 Along those lines — this is my first time doing Discord bot development, so I've not read over all features of discord.js. If there's something that would make sense for me to use and I'm not, it's probably because I haven't read that part of the docs yet and don't know about it, not an intentional choice :) |
When changing the channel status, the bot will update a previous embed if it's in the bottom 5 messages, rather than sending a new message. However, we were detecting *any* embed from the bot, rather than only status messages, so it would also replace playground links, for example. This detects status embeds by comparing their titles. In order to do that, it adds a title to the dormant embed. This isn't *necessary*; the following code would work instead: const isStatusEmbed = (embed: MessageEmbed) => ( embed.title === this.AVAILABLE_EMBED.title || embed.title === this.OCCUPIED_EMBED_BASE.title || embed.description === this.DORMANT_EMBED.description ); However, this way is both cleaner code-wise, and I think it's nice for all the status embeds to have the same format.
Got the bot up and running, but there's some permission errors and it's not creating channels for me like I believe it should. Not sure if I've misconfigured it. Hopefully I can figure that out soon or someone else who's gotten the bot to work in the past can try running this branch. In any case, it's working enough for me to get a screenshot of the embed: Takeaways:
|
- "To @person" looks awkward; dropped the "To " - Mentions don't work in the footer, just use the username instead
The embed looks good to me now. Fixed a few configuration problems but I still haven't gotten the bot to connect to postgres. It hangs at the Lines 8 to 26 in a4c9050
Thus, I can't test everything yet, although the bits that I have been able to test seem to be working as intended. |
I know the cause - sorry. The database provider we use made SSL required and I did a quick hotfix so we could get the help channels back online. If you remove these lines it'll work fine: ssl: true,
extra: {
ssl: {
rejectUnauthorized: false,
},
}, do you think you could put it behind a |
ok, I found the reason I was having trouble: for some reason, the very first character of the db url is dropped. DATABASE_URL=" tscbot:tscbot@localhost:5432/tscbot" |
This worked — should I add it to this PR or send another? |
Feel free to put it in this PR |
When running the bot locally, for development, SSL is an unnecessary extra setup step that makes it harder to get started.
Just tested locally, works well. Could you change the bullet points to the ones you came up with? After that we can do a full review and get it merged 👍 |
IMO the tsplay.dev link is still useful because the bot won't shorten links over 2000 chars (discord message limit). It might be worthwhile for the bot to download |
Turns out the array of messages is sorted with the most recent message first. By reversing the array, the bot would sometimes edit a higher-up status embed rather than the most recent one.
How's this for an updated message? const occupiedMessage = (asker: User) => `
**This channel is claimed by ${asker.toString()}.**
It is dedicated to answering their questions only.
**${asker.toString()} These things make your questions easier to answer:**
• Describe what you want to happen, and what happens instead.
• Copy-paste a short snippet (5-15 lines) that shows the problem.
• Start code blocks with \`\\\`\`ts for syntax highlighting.
• Try to reproduce your problem in the [TypeScript Playground](https://www.typescriptlang.org/play).
Usually someone will try to answer and help solve the issue within a few hours. If not, you may ping the @Helper role and ask what would make your question more likely to get an answer.
For more tips, check out StackOverflow's guide on **[asking good questions](https://stackoverflow.com/help/how-to-ask)**.
`; |
Updates the text to reflect things we commonly tell people with regard to asking good questions.
The message cache does not have a stable order (I suspect it is simply the order in which the messages were added to the cache). Thus, when searching for the latest status message, sometimes a message other than the latest was picked. In practice, it seems like this only ever happened when the bot was offline for a number of hours, which is why it hasn't come up in production. But in development, it could be reproduced by: - Leave the bot offline for a while (24h?) - Start the bot - Claim a channel - The channel that is moved up from being dormant has the wrong message edited, so the message at the bottom still says "dormant". I suspect this is what the `.reverse()`, which was removed in commit 09ad491, was intended to solve (but it caused bugs during normal operation). This should be a full fix. I am not sure of the performance implications here. I think it should not be too bad, because we are filtering to only messages from the bot, before sorting.
I think this is ready to be reviewed / merged. I updated the embed to be like this: I think 5c87f89 will have a minor performance impact, but I'm not sure how long the bot keeps messages in the cache. In the future, I'm interested in pinning both the asked question and the bot's status message — this would also make the code for figuring out which message to update simpler. But I'll send that in a separate PR (if you're interested). |
Yeah, it should be fine, the performance impact will be minimal. |
src/modules/helpchan.ts
Outdated
@@ -39,6 +42,20 @@ This channel will be dedicated to answering your question only. Others will try | |||
For more tips, check out StackOverflow's guide on **[asking good questions](https://stackoverflow.com/help/how-to-ask)**. | |||
`; | |||
|
|||
const occupiedMessage = (asker: User) => ` | |||
**This channel is claimed by ${asker.toString()}.** | |||
It is dedicated to answering their questions only. |
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.
A little late on this, but maybe
It is dedicated to answering their questions only. | |
It is dedicated to answering their questions only; see <#${askHelpChannelId}> to claim your own. |
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.
Added just "More info: <#${askHelpChannelId}>", so it will fit on one line. Two lines distracts a little from the "This channel is claimed by" message on the line above, in my opinion (fixable by adding a newline, but then the message starts to become longer than I think it should be).
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.
Looks pretty good! Just one small suggestion that can possibly clean it up a bit.
I'm busy for a few hours, will likely get to this tonight or tomorrow morning |
Based on code review & feedback: - Drop explicit `.toString()` in the template. - Add a link to the how-to-get-help channel. - Be explicit that code blocks > screenshots. - Be explicit that it may be impossible to reproduce in the playground.
It was setting the person who wrote "!claim", rather than the person who the channel was being claimed for.
This looks done to me. @smichel17 @ronthecookie ready to merge? |
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.
LGTM
Ready on my end. I have a handful of things I still want to do (e.g. didn't add back the channel topic change) but there's no reason they have to be in this PR. |
🚀 |
Context in commits. The code is mostly done but completely untested, because I haven't got the bot set up yet (need to request a Discord bot api key, etc). I'll probably get to that soon, but I also wanted to open a dialog here in case there's any changes you'd like me to make (and to make sure you're interested in merging, before spending too much time on this).