Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ SERVER_ID=your-server-id
# Channel IDs (from your dev server)
GUIDES_CHANNEL_ID=your-guide-channel-id
REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id
ONBOARDING_CHANNEL_ID=onboarding-channel-id

# Role IDs (from your dev server)
REPEL_ROLE_ID=your-repel-role-id
MODERATORS_ROLE_IDS=your-moderator-role-id

ONBOARDING_ROLE_ID=onboarding-role-id
# Other
GUIDES_TRACKER_PATH=guides-tracker.json
GUIDES_TRACKER_PATH=guides-tracker.json


2 changes: 1 addition & 1 deletion src/commands/moderation/repel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from 'discord.js';
import { HOUR, MINUTE, timeToString } from '../../constants/time.js';
import { config } from '../../env.js';
import { logToChannel } from '../../util/channel-logging.js';
import { getPublicChannels } from '../../util/channel.js';
import { logToChannel } from '../../util/channel-logging.js';
import { buildCommandString, createCommand } from '../../util/commands.js';

const DEFAULT_LOOK_BACK_MS = 10 * MINUTE;
Expand Down
22 changes: 22 additions & 0 deletions src/commands/onboarding/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ContainerBuilder,
type MessageActionRowComponentBuilder,
} from 'discord.js';

// Exported at the bottom after all child components are added
const containerComponent = new ContainerBuilder();

const actionRowComponent = new ActionRowBuilder<MessageActionRowComponentBuilder>();

const buttonComponent = new ButtonBuilder()
.setCustomId('onboarding_add_role')
.setLabel('Add role')
.setStyle(ButtonStyle.Primary);

actionRowComponent.addComponents(buttonComponent);
containerComponent.addActionRowComponents(actionRowComponent);

export { containerComponent };
54 changes: 54 additions & 0 deletions src/commands/onboarding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ApplicationCommandType, MessageFlags } from 'discord.js';
import { config } from '../../env.js';
import { addRoleToUser } from '../../util/addRoleToUser.js';
import { createCommand } from '../../util/commands.js';
import { containerComponent } from './component.js';

export const onboardingCommand = createCommand({
data: {
name: 'onboarding',
description: 'Manage onboarding settings',
type: ApplicationCommandType.ChatInput,
},
execute: async (interaction) => {
const guild = interaction.guild;
if (!guild) {
await interaction.reply({
content: 'This command can only be used in a server.',
flags: MessageFlags.Ephemeral,
});
return;
}
Comment on lines +15 to +21
Copy link
Member

Choose a reason for hiding this comment

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

idea for future: should add a custom function that does exactly this check.

const onboardingRole = guild.roles.cache.get(config.onboarding.roleId);
if (!onboardingRole) {
await interaction.reply({
content: 'Onboarding role not found. Please check the configuration.',
flags: MessageFlags.Ephemeral,
});
return;
}
const onboardingChannel = guild.channels.cache.get(config.onboarding.channelId);
if (!onboardingChannel || !onboardingChannel.isSendable()) {
await interaction.reply({
content:
'Onboarding channel not found or is not a text channel. Please check the configuration.',
flags: MessageFlags.Ephemeral,
});
return;
}

const onboardingMessage = await interaction.reply({
components: [containerComponent],
flags: MessageFlags.IsComponentsV2,
});

const collector = onboardingMessage.createMessageComponentCollector({});

collector.on('collect', async (componentInteraction) => {
if (componentInteraction.customId === 'onboarding_add_role') {
const member = await guild.members.fetch(componentInteraction.user.id);
await addRoleToUser(member, onboardingRole, componentInteraction);
}
});
},
});
11 changes: 11 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export const config = {
channelId: requireEnv('GUIDES_CHANNEL_ID'),
trackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
},
onboarding: {
channelId: requireEnv('ONBOARDING_CHANNEL_ID'),
roleId: requireEnv('ONBOARDING_ROLE_ID'),
},
// Add more config sections as needed:
// database: {
// url: requireEnv('DATABASE_URL'),
// },
// api: {
// openaiKey: optionalEnv('OPENAI_API_KEY'),
// },
};

export type Config = typeof config;
Expand Down
40 changes: 40 additions & 0 deletions src/util/addRoleToUser.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

imo file names should be kebab-case

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
type ButtonInteraction,
type CacheType,
type ChannelSelectMenuInteraction,
type GuildMember,
type MentionableSelectMenuInteraction,
MessageFlags,
type Role,
type RoleSelectMenuInteraction,
type StringSelectMenuInteraction,
type UserSelectMenuInteraction,
} from 'discord.js';

type ComponentInteraction =
| ButtonInteraction<CacheType>
| StringSelectMenuInteraction<CacheType>
| UserSelectMenuInteraction<CacheType>
| RoleSelectMenuInteraction<CacheType>
| MentionableSelectMenuInteraction<CacheType>
| ChannelSelectMenuInteraction<CacheType>;

export async function addRoleToUser(
member: GuildMember,
role: Role,
interaction: ComponentInteraction
) {
const hasRole = member.roles.cache.has(role.id);
if (hasRole) {
await interaction.reply({
content: `You already have the ${role.name} role.`,
flags: MessageFlags.Ephemeral,
});
} else {
await member.roles.add(role);
await interaction.reply({
content: `You have been given the ${role.name} role!`,
flags: MessageFlags.Ephemeral,
});
}
}
Copy link
Contributor Author

@hmd-ali hmd-ali Nov 5, 2025

Choose a reason for hiding this comment

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

This should handle only the the role part, i.e checking for the role we're assigning and adding it to the user. It should return a boolean that we can use to then handle what we want to do in the consuming file
in this case we would reply to the interaction.