Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ADVENT_OF_CODE_CHANNEL_ID=1047623689488830495
# Role IDs (from your dev server)
REPEL_ROLE_ID=1002411741776461844
MODERATORS_ROLE_IDS=849481536654803004
REGULAR_ROLE_ID=1383170370634514544

# Other
GUIDES_TRACKER_PATH=/app/data/guides-tracker.json
Expand Down
2 changes: 1 addition & 1 deletion src/commands/docs/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
} from 'discord.js';
import { features as data } from 'web-features';
import { fuzzySearch } from '../../util/fuzzy-search.js';
import { clampText } from '../../util/text.js';
import type { ProviderConfig } from './types.js';
import { createBaseConfig, getBaselineFeatures } from './utils.js';
import { clampText } from '../../util/text.js';

export type FeatureData = {
name: string;
Expand Down
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const config = {
? requireEnv('MODERATORS_ROLE_IDS').split(',')
: [],
repel: requireEnv('REPEL_ROLE_ID'),
regular: requireEnv('REGULAR_ROLE_ID'),
a: optionalEnv('ROLE_A_ID'),
b: optionalEnv('ROLE_B_ID'),
c: optionalEnv('ROLE_C_ID'),
Expand Down
28 changes: 24 additions & 4 deletions src/events/just-ask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Events } from 'discord.js';
import { Events, type Message, PermissionFlagsBits } from 'discord.js';
import { MINUTE } from '../constants/time.js';
import { config } from '../env.js';
import { createEvent } from '../util/events.js';
import { loadMarkdownOptions } from '../util/markdown.js';
import { rateLimit } from '../util/rate-limit.js';
Expand All @@ -20,7 +21,7 @@ const reQuestion = `(?:experience|knowledge|info(?:rmation)?|ideas?|clues?|tips?
const reConnector = `(?:with|about|on|regarding|for|of)`;

const askToAskPattern = new RegExp(
String.raw`\b${reSubject}\s+${reVerb}\s+(?:${reQuantifier}\s+)?(?:${reQuestion}\s+)?(?:${reConnector}\s+)?.+\??`,
String.raw`\b${reSubject}\s+${reVerb}\s+(?:${reQuantifier}\s+)?(?:${reQuestion}\s+)?(?:${reConnector}\s+)?.+\?`,
'i'
);

Expand All @@ -33,15 +34,34 @@ const [response] = await loadMarkdownOptions<{ name: string }>(

const { canRun, reset } = rateLimit(10 * MINUTE);

const shouldCheck = (message: Message) => {
// check rate limit
if (!canRun()) {
return false;
}
// check author
if (message.author.bot || message.author.system) {
return false;
}
// check roles/permissions
if (
message.member !== null &&
(message.member.roles.highest.comparePositionTo(config.roleIds.repel) >= 0 ||
message.member.permissions.has(PermissionFlagsBits.ModerateMembers))
) {
return false;
}
return true;
};

export const justAskEvent = createEvent(
{
name: Events.MessageCreate,
},
async (message) => {
if (!canRun() || message.author.bot) {
if (!shouldCheck(message)) {
return;
}

// Ignore long messages, likely user provided more context
if (message.content.split(' ').length > 10) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/util/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChatInputCommandInteraction, Client } from 'discord.js';
import type { ChatInputCommandInteraction } from 'discord.js';
import type { Command } from '../commands/types.js';

export const createCommand = (command: Command): Command => {
Expand Down
Loading