-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
546 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
node_modules | ||
pnpm-lock.yaml | ||
.env | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3.9" | ||
services: | ||
bot: | ||
image: "mrbazlow/warbot:latest" | ||
restart: always | ||
volumes: | ||
- ./data:/opt/app/data | ||
env_file: | ||
- ./.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { TextChannel, codeBlock } from 'discord.js' | ||
import { Command } from '@sapphire/framework' | ||
import { table } from 'table' | ||
|
||
import type { TableUserConfig } from 'table' | ||
|
||
const CHANNEL_ID = '1097620947713933393' | ||
|
||
export class UserCommand extends Command { | ||
public constructor(context: Command.Context, options: Command.Options) { | ||
super(context, { | ||
...options, | ||
name: 'enlistmenthistory', | ||
description: 'Lookup a users verification history' | ||
}) | ||
} | ||
|
||
public override registerApplicationCommands(registry: Command.Registry) { | ||
registry.registerChatInputCommand((builder) => { | ||
builder // | ||
.setName(this.name) | ||
.setDescription(this.description) | ||
.addStringOption((option) => | ||
option // | ||
.setName('user') | ||
.setDescription('Discord user to lookup') | ||
.setRequired(true) | ||
) | ||
}) | ||
} | ||
|
||
public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) { | ||
interaction.client.logger.info( | ||
`${interaction.user.tag} in #${ | ||
interaction.channel instanceof TextChannel ? interaction.channel.name : 'somewhere' | ||
} called enlistmenthistory.` | ||
) | ||
|
||
await interaction.deferReply() | ||
|
||
const channel = interaction.client.channels.cache.get(CHANNEL_ID) | ||
|
||
const user = interaction.options.getString('user') ?? 'mystery user' | ||
|
||
if (channel instanceof TextChannel) { | ||
channel.messages | ||
.fetch() | ||
.then((messages) => { | ||
return messages.filter((message) => { | ||
message.content.includes(`Approved by ${user}`) | ||
}) | ||
}) | ||
.then((filteredMessages) => { | ||
console.log(user) | ||
console.log(filteredMessages) | ||
}) | ||
.catch((error) => console.error(error)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Command } from '@sapphire/framework' | ||
import { createPartitionedMessageRow } from '@sapphire/discord.js-utilities' | ||
import { EmbedBuilder, ButtonBuilder, ButtonStyle } from 'discord.js' | ||
import errorMessage from '../lib/errorMessage.js' | ||
import { regionFriendlyNamesSchema } from '../schema.js' | ||
import { Time } from '@sapphire/time-utilities' | ||
import { Value } from '@sinclair/typebox/value' | ||
|
||
export class UserCommandCreateButton extends Command { | ||
public regionFriendlyNames = Value.Create(regionFriendlyNamesSchema) | ||
|
||
public constructor(context: Command.Context, options: Command.Options) { | ||
super(context, { | ||
...options, | ||
name: 'qrf', | ||
description: `Create a QRF Alert` | ||
}) | ||
} | ||
|
||
public override registerApplicationCommands(registry: Command.Registry) { | ||
registry.registerChatInputCommand((builder) => { | ||
builder // | ||
.setName(this.name) | ||
.setDescription(this.description) | ||
.addStringOption((option) => | ||
option // | ||
.setName('region') | ||
.setDescription('Region to check') | ||
.setAutocomplete(true) | ||
.setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option // | ||
.setName('description') | ||
.setDescription('QRF details') | ||
.setRequired(true) | ||
) | ||
.addAttachmentOption((option) => | ||
option // | ||
.setName('screenshot') | ||
.setDescription('Image to include in your QRF Message') | ||
.setRequired(true) | ||
) | ||
}) | ||
} | ||
|
||
public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) { | ||
await interaction.deferReply() | ||
const userAvatar = interaction.user.avatarURL() ?? '' | ||
const region = interaction.options.getString('region') as keyof typeof this.regionFriendlyNames | ||
const description = interaction.options.getString('description') ?? '' | ||
const image = interaction.options.getAttachment('screenshot') | ||
|
||
try { | ||
if (!Object.hasOwn(this.regionFriendlyNames, region)) { | ||
await interaction.editReply(`"${region}" is not a location in Foxhole`) | ||
setTimeout(() => { | ||
void interaction.deleteReply().catch((error: unknown) => { | ||
interaction.client.logger.error(error) | ||
}) | ||
}, Time.Second * 5) | ||
return | ||
} | ||
if (image === null) { | ||
throw new Error('Unable to find image') | ||
} | ||
if (interaction.channel?.isTextBased()) { | ||
const qrfEmbed = new EmbedBuilder() | ||
.setAuthor({ name: interaction.user.tag, iconURL: userAvatar }) | ||
.setTitle(`Help ${this.regionFriendlyNames[region]}!`) | ||
.setDescription(description) | ||
.setImage(image.url) | ||
.setColor('#245682') | ||
.setFields( | ||
{ name: 'Status', value: '🔴 ONGOING', inline: true }, | ||
{ name: 'OP', value: interaction.user.toString(), inline: true }, | ||
{ name: 'Responders', value: interaction.user.toString(), inline: true } | ||
) | ||
.setTimestamp(Date.now()) | ||
.setFooter({ | ||
text: 'QRF Request', | ||
iconURL: | ||
'https://cdn.discordapp.com/attachments/1025869440451100742/1099895163662372875/rotating_light.png' | ||
}) | ||
|
||
const submitButton = new ButtonBuilder() // | ||
.setCustomId('qrfSubmit') | ||
.setEmoji('📩') | ||
.setLabel('Submit') | ||
.setStyle(ButtonStyle.Success) | ||
const cancelButton = new ButtonBuilder() // | ||
.setCustomId('qrfCancel') | ||
.setEmoji('🛑') | ||
.setLabel('Cancel') | ||
.setStyle(ButtonStyle.Secondary) | ||
|
||
await interaction.editReply({ | ||
embeds: [qrfEmbed], | ||
components: createPartitionedMessageRow([submitButton, cancelButton]) | ||
}) | ||
} | ||
} catch (error) { | ||
void errorMessage(error, interaction) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework' | ||
import { ButtonInteraction } from 'discord.js' | ||
import errorMessage from '../lib/errorMessage.js' | ||
|
||
export class ButtonHandler extends InteractionHandler { | ||
public constructor(ctx: PieceContext, options: InteractionHandler.Options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.Button | ||
}) | ||
} | ||
|
||
public override parse(interaction: ButtonInteraction) { | ||
if (interaction.customId !== 'qrfCancel') { | ||
return this.none() | ||
} | ||
const originalPosterId = interaction.message.embeds[0].fields.find( | ||
(field) => field.name === 'OP' | ||
)?.value | ||
if (interaction.user.toString() === originalPosterId) { | ||
return this.some() | ||
} | ||
return this.none() | ||
} | ||
|
||
public async run(interaction: ButtonInteraction) { | ||
await interaction.deferReply({ ephemeral: true }) | ||
try { | ||
await interaction.message.delete() | ||
await interaction.deleteReply() | ||
} catch (error) { | ||
void errorMessage(error, interaction) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework' | ||
import errorMessage from '../lib/errorMessage.js' | ||
import { EmbedBuilder } from 'discord.js' | ||
|
||
import type { ButtonInteraction } from 'discord.js' | ||
|
||
export class ButtonHandler extends InteractionHandler { | ||
public constructor(ctx: PieceContext, options: InteractionHandler.Options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.Button | ||
}) | ||
} | ||
|
||
public override parse(interaction: ButtonInteraction) { | ||
if (interaction.customId !== 'qrfIgnore') { | ||
return this.none() | ||
} | ||
return this.some() | ||
} | ||
|
||
public async run(interaction: ButtonInteraction) { | ||
await interaction.deferReply({ ephemeral: true }) | ||
|
||
try { | ||
const username = interaction.user.toString() | ||
const oldEmbed = interaction.message.embeds[0] | ||
const respondersField = oldEmbed.fields.find((entry) => entry.name === 'Responders') | ||
if (respondersField?.value.includes(username)) { | ||
respondersField.value = respondersField.value.replaceAll(`, ${username}`, '') | ||
respondersField.value = respondersField.value.replaceAll(username, '') | ||
const newEmbed = new EmbedBuilder(oldEmbed.toJSON()) | ||
await interaction.message.edit({ | ||
embeds: [newEmbed] | ||
}) | ||
await interaction.message.thread?.members.remove( | ||
interaction.user.id, | ||
`${username} requested to leave the QRF Event` | ||
) | ||
} | ||
await interaction.deleteReply() | ||
} catch (error) { | ||
void errorMessage(error, interaction) | ||
} | ||
} | ||
} |
Oops, something went wrong.