Skip to content

Commit

Permalink
Add hidden group and competition moderation controls (#256)
Browse files Browse the repository at this point in the history
* Add hidden group moderation controls

* Add hidden competition moderation controls
  • Loading branch information
rorro authored Jul 19, 2024
1 parent e584072 commit 9794c9d
Show file tree
Hide file tree
Showing 14 changed files with 600 additions and 43 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@sapphire/discord.js-utilities": "^7.1.6",
"@sentry/node": "^7.28.0",
"@sentry/tracing": "^7.28.0",
"@wise-old-man/utils": "^3.3.1",
"@wise-old-man/utils": "^3.3.3",
"canvas": "^2.6.1",
"cors": "^2.8.5",
"discord.js": "^14.14.1",
Expand Down
19 changes: 7 additions & 12 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import {
TextChannel,
GatewayIntentBits,
ChannelType,
PermissionFlagsBits,
Options
Options,
PermissionFlagsBits
} from 'discord.js';
import config from './config';
import * as router from './commands/router';
import {
PATREON_MODAL_ID,
PATREON_TRIGGER_ID,
handlePatreonModalSubmit,
handlePatreonTrigger,
setupPatreonTrigger
} from './patreon-trigger';
import { PATREON_MODAL_ID, handlePatreonModalSubmit, setupPatreonTrigger } from './patreon-trigger';
import { handleButtonInteraction } from './utils/buttonInteractions';

const CACHED_ACTIVE_USER_IDS = new Set<string>(config.discord.cache.excludeUsers);
const CACHED_ACTIVE_GUILD_IDS = new Set<string>(config.discord.cache.excludeGuilds);
Expand Down Expand Up @@ -79,9 +74,9 @@ class Bot {
this.client.user?.setActivity('bot.wiseoldman.net');

// Send received interaction to the command router
this.client.on('interactionCreate', (interaction: Interaction) => {
if (interaction.isButton() && interaction.customId === PATREON_TRIGGER_ID) {
handlePatreonTrigger(interaction);
this.client.on('interactionCreate', async (interaction: Interaction) => {
if (interaction.isButton()) {
handleButtonInteraction(interaction);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/commands/instances/group/GroupGainedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import {
getMetricName,
isMetric,
Metric,
parseMetricAbbreviation,
parsePeriodExpression,
PeriodProps
} from '@wise-old-man/utils';
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import womClient from '../../../services/wiseoldman';
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
import config from '../../../config';
import { Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId, bold } from '../../../utils';

Expand Down
10 changes: 2 additions & 8 deletions src/commands/instances/group/GroupHiscoresCommand.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
formatNumber,
getMetricName,
GroupHiscoresEntry,
Metric,
parseMetricAbbreviation
} from '@wise-old-man/utils';
import { formatNumber, getMetricName, GroupHiscoresEntry, Metric } from '@wise-old-man/utils';
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import womClient from '../../../services/wiseoldman';
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
import config from '../../../config';
import { bold, Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';

Expand Down
3 changes: 1 addition & 2 deletions src/commands/instances/group/GroupRecordsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import {
isMetric,
isPeriod,
Metric,
parseMetricAbbreviation,
Period,
PeriodProps,
PERIODS
} from '@wise-old-man/utils';
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import womClient from '../../../services/wiseoldman';
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
import config from '../../../config';
import { bold, Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';

Expand Down
12 changes: 2 additions & 10 deletions src/commands/instances/player/PlayerGainedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ class PlayerGainedCommand extends Command {
}
}

function buildPages(
displayName: string,
period: string,
gained: GetPlayerGainsResponse<PlayerDeltasMap>
) {
function buildPages(displayName: string, period: string, gained: GetPlayerGainsResponse) {
const gainsList = buildGainsList(displayName, period, gained);
const pageCount = Math.ceil(gainsList.length / GAINS_PER_PAGE);

Expand All @@ -137,11 +133,7 @@ function buildPages(
return pages;
}

function buildGainsList(
displayName: string,
period: string,
gained: GetPlayerGainsResponse<PlayerDeltasMap>
) {
function buildGainsList(displayName: string, period: string, gained: GetPlayerGainsResponse) {
const computedGains = Array.from(Object.entries(gained.data.computed))
.filter(([, e]) => e.value.gained > 0)
.map(([key, val]) => ({ metric: key, gained: val.value.gained }))
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default {
flags: env.DISCORD_DEV_FLAG_CHANNEL_ID || '802680940835897384',
modLogs: env.DISCORD_DEV_MODSLOGS_CHANNEL_ID || '830199626630955039',
patreonInfo: env.DISCORD_DEV_PATREON_INFO_CHANNEL_ID || '1173680059526152272',
flaggedPlayerReviews: env.DISCORD_DEV_FLAGGED_REVIEWS_CHANNEL_ID || '1086637095415722169'
flaggedPlayerReviews: env.DISCORD_DEV_FLAGGED_REVIEWS_CHANNEL_ID || '1086637095415722169',
underAttackModeFeed: env.DISCORD_DEV_UNDER_ATTACK_MODE_FEED_CHANNEL_ID || '1263280946753441937'
},
cache: {
excludeUsers: [
Expand Down
41 changes: 41 additions & 0 deletions src/events/instances/HiddenCompetitionCreated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ChannelType, Client, EmbedBuilder, TextChannel } from 'discord.js';
import { encodeURL, Event } from '../../utils';
import { CompetitionListItem } from '@wise-old-man/utils';
import { createModerationButtons, ModerationType } from '../../utils/buttonInteractions';
import config from '../../config';

class HiddenCompetitionCreated implements Event {
type: string;

constructor() {
this.type = 'HIDDEN_COMPETITION_CREATED';
}

async execute(data: CompetitionListItem, client: Client) {
const { id, title, groupId, participantCount } = data['competition'];

const actions = createModerationButtons(ModerationType.COMPETITION, id);

const message = new EmbedBuilder()
.setColor(config.visuals.blue)
.setTitle(`A hidden competition was created`)
.setDescription(
`Id: ${id}\nTitle: ${title}\nParticipants: ${participantCount}\nGroup Id: ${
groupId ? '[' + groupId + '](https://wiseoldman.net/groups/' + groupId + ')' : groupId
}`
)
.setURL(encodeURL(`https://wiseoldman.net/competitions/${id}`));

const reviewChannel = client.channels?.cache.get(config.discord.channels.underAttackModeFeed);
if (!reviewChannel) return;
if (!((channel): channel is TextChannel => channel.type === ChannelType.GuildText)(reviewChannel))
return;

await reviewChannel.send({
embeds: [message],
components: [actions]
});
}
}

export default new HiddenCompetitionCreated();
38 changes: 38 additions & 0 deletions src/events/instances/HiddenGroupCreated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ChannelType, Client, EmbedBuilder, TextChannel } from 'discord.js';
import { Event } from '../../utils/events';
import { GroupListItem } from '@wise-old-man/utils';
import config from '../../config';
import { encodeURL } from '../../utils';
import { createModerationButtons, ModerationType } from '../../utils/buttonInteractions';

class HiddenGroupCreated implements Event {
type: string;

constructor() {
this.type = 'HIDDEN_GROUP_CREATED';
}

async execute(data: GroupListItem, client: Client) {
const { id, name, description, memberCount } = data['group'];

const actions = createModerationButtons(ModerationType.GROUP, id);

const message = new EmbedBuilder()
.setColor(config.visuals.blue)
.setTitle(`A hidden group was created`)
.setDescription(`Id: ${id}\nName: ${name}\nDescription: ${description}\nMembers: ${memberCount}`)
.setURL(encodeURL(`https://wiseoldman.net/groups/${id}`));

const reviewChannel = client.channels?.cache.get(config.discord.channels.underAttackModeFeed);
if (!reviewChannel) return;
if (!((channel): channel is TextChannel => channel.type === ChannelType.GuildText)(reviewChannel))
return;

await reviewChannel.send({
embeds: [message],
components: [actions]
});
}
}

export default new HiddenGroupCreated();
6 changes: 5 additions & 1 deletion src/events/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import MembersJoined from './instances/MembersJoined';
import MembersLeft from './instances/MembersLeft';
import PlayerFlaggedReview from './instances/PlayerFlaggedReview';
import MembersRolesChanged from './instances/MembersRolesChanged';
import HiddenGroupCreated from './instances/HiddenGroupCreated';
import HiddenCompetitionCreated from './instances/HiddenCompetitionCreated';

const EVENTS: Event[] = [
CompetitionCreated,
Expand All @@ -26,7 +28,9 @@ const EVENTS: Event[] = [
MemberHardcoreDied,
MemberAchievements,
PlayerFlaggedReview,
MembersRolesChanged
MembersRolesChanged,
HiddenGroupCreated,
HiddenCompetitionCreated
];

function onEventReceived(client: Client, payload: { type: string; data: unknown }): void {
Expand Down
Loading

0 comments on commit 9794c9d

Please sign in to comment.