Skip to content

Commit 9a11a61

Browse files
authored
Merge pull request #195 from tjjfvi/how-to-give-help
Create a #how-to-give-help channel
2 parents 77a7726 + 36f424b commit 9a11a61

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ TRUSTED_ROLE_ID=
1313

1414
RULES_CHANNEL=
1515

16+
ROLES_CHANNEL=
17+
1618
HELP_CATEGORY=
1719
HOW_TO_GET_HELP_CHANNEL=
20+
HOW_TO_GIVE_HELP_CHANNEL=
1821
GENERAL_HELP_CHANNEL=
1922

2023
# Time in milliseconds before !helper can be run

src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ export const dbUrl = process.env.DATABASE_URL!;
1818

1919
export const helpCategory = process.env.HELP_CATEGORY!;
2020
export const howToGetHelpChannel = process.env.HOW_TO_GET_HELP_CHANNEL!;
21+
export const howToGiveHelpChannel = process.env.HOW_TO_GIVE_HELP_CHANNEL!;
2122
export const generalHelpChannel = process.env.GENERAL_HELP_CHANNEL!;
2223

2324
export const trustedRoleId = process.env.TRUSTED_ROLE_ID!;
2425

2526
export const rulesChannelId = process.env.RULES_CHANNEL!;
2627

28+
export const rolesChannelId = process.env.ROLES_CHANNEL!;
29+
2730
export const TS_BLUE = '#007ACC';
2831
export const GREEN = '#3ba55d';
2932
// Picked from Discord's blockquote line

src/modules/helpthread.ts

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
BLOCKQUOTE_GREY,
1818
generalHelpChannel,
1919
howToGetHelpChannel,
20+
howToGiveHelpChannel,
21+
rolesChannelId,
2022
} from '../env';
2123
import { isTrustedMember } from '../util/inhibitors';
2224
import { sendWithMessageOwnership } from '../util/send';
@@ -38,9 +40,6 @@ If your issue is not resolved, **you can post another message here and the threa
3840
*If you have a different question, just ask in <#${generalHelpChannel}>.*
3941
`);
4042

41-
// A zero-width space (necessary to prevent discord from trimming the leading whitespace), followed by a three non-breaking spaces.
42-
const indent = '\u200b\u00a0\u00a0\u00a0';
43-
4443
const closedEmoji = '☑️';
4544

4645
const helpInfo = (channel: TextChannel) =>
@@ -53,29 +52,29 @@ const howToGetHelpEmbeds = () => [
5352
.setColor(GREEN)
5453
.setTitle('How To Get Help')
5554
.setDescription(
56-
`
57-
Post your question to one of the channels in this category.
58-
${indent} If you're not sure which channel is best, just post in <#${generalHelpChannel}>.
59-
${indent} It's always ok to just ask your question; you don't need permission.
60-
Our bot will make a thread dedicated to answering your channel.
61-
Someone will (hopefully!) come along and help you.
62-
When your question is resolved, type \`!close\`.
63-
`,
55+
listify(`
56+
- Post your question to one of the channels in this category.
57+
- If you're not sure which channel is best, just post in <#${generalHelpChannel}>.
58+
- It's always ok to just ask your question; you don't need permission.
59+
- Our bot will make a thread dedicated to answering your channel.
60+
- Someone will (hopefully!) come along and help you.
61+
- When your question is resolved, type \`!close\`.
62+
`),
6463
),
6564
new MessageEmbed()
6665
.setColor(GREEN)
6766
.setTitle('How To Get *Better* Help')
6867
.setDescription(
69-
`
70-
Explain what you want to happen and why…
71-
${indent} …and what actually happens, and your best guess at why.
72-
Include a short code sample and any error messages you got.
73-
${indent} Text is better than screenshots. Start code blocks with ${'\\`\\`\\`ts'}.
74-
If possible, create a minimal reproduction in the **[TypeScript Playground](https://www.typescriptlang.org/play)**.
75-
${indent} Send the full link in its own message; do not use a link shortener.
76-
Run \`!title <brief description>\` to make your help thread easier to spot.
77-
For more tips, check out StackOverflow's guide on **[asking good questions](https://stackoverflow.com/help/how-to-ask)**.
78-
`,
68+
listify(`
69+
- Explain what you want to happen and why…
70+
- …and what actually happens, and your best guess at why.
71+
- Include a short code sample and any error messages you got.
72+
- Text is better than screenshots. Start code blocks with ${'\\`\\`\\`ts'}.
73+
- If possible, create a minimal reproduction in the **[TypeScript Playground](https://www.typescriptlang.org/play)**.
74+
- Send the full link in its own message; do not use a link shortener.
75+
- Run \`!title <brief description>\` to make your help thread easier to spot.
76+
- For more tips, check out StackOverflow's guide on **[asking good questions](https://stackoverflow.com/help/how-to-ask)**.
77+
`),
7978
),
8079
new MessageEmbed()
8180
.setColor(GREEN)
@@ -88,6 +87,46 @@ If not, and if you have followed the bullets above, you can ping helpers by runn
8887
),
8988
];
9089

90+
const howToGiveHelpEmbeds = () => [
91+
new MessageEmbed()
92+
.setColor(GREEN)
93+
.setTitle('How To Give Help')
94+
.setDescription(
95+
listify(`
96+
- There are a couple ways you can browse help threads:
97+
- The channel sidebar on the left will list threads you have joined.
98+
- You can scroll through the channel to see all recent questions.
99+
- The bot will mark closed questions with ${closedEmoji}.
100+
- In the channel, you can click the *⌗*\u2004icon at the top right to view threads by title.
101+
102+
`),
103+
),
104+
new MessageEmbed()
105+
.setColor(GREEN)
106+
.setTitle('How To Give *Better* Help')
107+
.setDescription(
108+
listify(`
109+
- Get yourself the <@&${trustedRoleId}> role at <#${rolesChannelId}>
110+
- (If you don't like the pings, you can disable role mentions for the server.)
111+
- As a <@&${trustedRoleId}>, you can:
112+
- Run \`!title <brief description>\` to set/update the thread title.
113+
- This will assist other helpers in finding the thread.
114+
- Also, it means your help is more accessible to others in the future.
115+
- If a thread appears to be resolved, run \`!close\` to close it.
116+
- *Only do this if the asker has indicated that their question has been resolved.*
117+
`),
118+
),
119+
new MessageEmbed()
120+
.setColor(GREEN)
121+
.setTitle('Useful Snippets')
122+
.setDescription(
123+
listify(`
124+
- \`!screenshot\` — for if an asker posts a screenshot of code
125+
- \`!ask\` — for if an asker only posts "can I get help?"
126+
`),
127+
),
128+
];
129+
91130
const helpThreadWelcomeMessage = (owner: GuildMember) => `
92131
${owner} This thread is for your question; type \`!title <brief description>\`. \
93132
When it's resolved, please type \`!close\`. \
@@ -340,13 +379,18 @@ export class HelpThreadModule extends Module {
340379

341380
@command()
342381
async htgh(msg: Message) {
382+
if (!msg.member?.permissions.has('MANAGE_MESSAGES')) return;
343383
if (
344-
msg.channel.id !== howToGetHelpChannel ||
345-
!msg.member?.permissions.has('MANAGE_MESSAGES')
384+
msg.channel.id !== howToGetHelpChannel &&
385+
msg.channel.id !== howToGiveHelpChannel
346386
)
347387
return;
348388
(await msg.channel.messages.fetch()).forEach(x => x.delete());
349-
msg.channel.send({ embeds: howToGetHelpEmbeds() });
389+
const embeds =
390+
msg.channel.id === howToGetHelpChannel
391+
? howToGetHelpEmbeds()
392+
: howToGiveHelpEmbeds();
393+
msg.channel.send({ embeds });
350394
}
351395
}
352396

@@ -356,7 +400,8 @@ export function isHelpChannel(
356400
return (
357401
channel instanceof TextChannel &&
358402
channel.parentId == helpCategory &&
359-
channel.id !== howToGetHelpChannel
403+
channel.id !== howToGetHelpChannel &&
404+
channel.id !== howToGiveHelpChannel
360405
);
361406
}
362407

@@ -365,3 +410,10 @@ export function isHelpThread(
365410
): channel is ThreadChannel & { parent: TextChannel } {
366411
return channel instanceof ThreadChannel && isHelpChannel(channel.parent!);
367412
}
413+
414+
function listify(text: string) {
415+
// A zero-width space (necessary to prevent discord from trimming the leading whitespace), followed by a three non-breaking spaces.
416+
const indent = '\u200b\u00a0\u00a0\u00a0';
417+
const bullet = '•';
418+
return text.replace(/^(\s*)-/gm, `$1${bullet}`).replace(/\t/g, indent);
419+
}

0 commit comments

Comments
 (0)