Skip to content

Commit 583a0ed

Browse files
authored
Merge pull request #160 from Retsam/less-at-helper-spam
Add a !helper command for pinging helpers
2 parents a27a172 + c8fb937 commit 583a0ed

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ CHANNEL_NAMES=list,help,channel,names,here,seperated,by,commas
2828
DORMANT_CHANNEL_TIMEOUT=
2929
DORMANT_CHANNEL_LOOP=
3030
ONGOING_EMPTY_TIMEOUT=
31+
TIME_BEFORE_HELPER_PING=

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
volumes:
2828
- 'postgres_data:/postgres/data'
2929
ports:
30-
- 5432:5432
30+
- 5432
3131

3232
volumes:
3333
postgres_data:

src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const dormantChannelLoop = parseInt(process.env.DORMANT_CHANNEL_LOOP!);
4040

4141
export const ongoingEmptyTimeout = parseInt(process.env.ONGOING_EMPTY_TIMEOUT!);
4242

43+
export const timeBeforeHelperPing = parseInt(
44+
process.env.TIME_BEFORE_HELPER_PING!,
45+
);
46+
4347
export const TS_BLUE = '#007ACC';
4448
export const GREEN = '#77b155';
4549
// Picked from Discord's "hourglass" emoji (in ⌛ | Occupied Help Channels)

src/modules/helpchan.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
GuildMember,
1515
ChannelData,
1616
CategoryChannel,
17-
GuildManager,
1817
Channel,
1918
} from 'discord.js';
2019
import { HelpUser } from '../entities/HelpUser';
@@ -32,6 +31,7 @@ import {
3231
ongoingEmptyTimeout,
3332
trustedRoleId,
3433
dormantChannelTimeoutHours,
34+
timeBeforeHelperPing,
3535
} from '../env';
3636
import { isTrustedMember } from '../util/inhibitors';
3737

@@ -66,13 +66,13 @@ If you want help, please ask in an available channel instead.
6666
• Explain what you want to happen and why…
6767
${u2800}• …and what actually happens, and your best guess at why.
6868
• Include a short code sample and error messages, if you got any.
69-
${u2800}• Text is better than screenshots. Start code blocks with ${'```ts'}.
69+
${u2800}• Text is better than screenshots. Start code blocks with ${'\\`\\`\\`ts'}.
7070
• If possible, create a minimal reproduction in the **[TypeScript Playground](https://www.typescriptlang.org/play)**.
7171
${u2800}• Send the full link in its own message. Do not use a link shortener.
7272
7373
For more tips, check out StackOverflow's guide on **[asking good questions](https://stackoverflow.com/help/how-to-ask)**.
7474
75-
Usually someone will try to answer and help solve the issue within a few hours. If not, and **if you have followed the bullets above**, you may ping the <@&${trustedRoleId}> role. Please allow extra time at night in America/Europe.
75+
Usually someone will try to answer and help solve the issue within a few hours. If not, and **if you have followed the bullets above**, you may ping the <@&${trustedRoleId}> role with \`!helper\`. Please allow extra time at night in America/Europe.
7676
`;
7777

7878
const DORMANT_MESSAGE = `
@@ -277,6 +277,48 @@ export class HelpChanModule extends Module {
277277
await msg.delete({ reason: 'Pin system message' });
278278
}
279279

280+
@command({
281+
description: 'Pings a helper in a help-channel',
282+
aliases: ['helpers'],
283+
})
284+
async helper(msg: Message) {
285+
if (msg.channel.type !== 'text') return;
286+
if (msg.channel.parentID !== categories.ongoing) {
287+
return msg.channel.send(
288+
':warning: You may only ping helpers from a help channel',
289+
);
290+
}
291+
292+
// Ensure the user has permission to ping helpers
293+
const asker = await HelpUser.findOne({
294+
channelId: msg.channel.id,
295+
});
296+
const isAsker = asker?.userId === msg.author.id;
297+
const isTrusted =
298+
(await isTrustedMember(msg, this.client)) === undefined; // No error if trusted
299+
if (!isAsker && !isTrusted) {
300+
return msg.channel.send(
301+
':warning: Only the asker can ping helpers',
302+
);
303+
}
304+
305+
// Ensure they've waited long enough
306+
// Trusted members (who aren't the asker) are allowed to disregard the timeout
307+
const askTime = msg.channel.lastPinTimestamp ?? 0;
308+
const pingAllowedAfter = askTime + timeBeforeHelperPing;
309+
310+
if (isAsker && Date.now() < pingAllowedAfter) {
311+
return msg.channel.send(
312+
`:warning: Please wait a bit longer. You can ping helpers <t:${
313+
pingAllowedAfter / 1000
314+
}:R>.`,
315+
);
316+
}
317+
318+
// The beacons are lit, Gondor calls for aid
319+
msg.channel.send(`<@&${trustedRoleId}>`);
320+
}
321+
280322
@command({
281323
aliases: ['close', 'closed', 'resolve', 'done'],
282324
description: 'Help Channel: Marks this channel as resolved',

0 commit comments

Comments
 (0)