Skip to content

Commit

Permalink
fix: add hall of fame condition for youtube videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Battlesquid committed Jul 11, 2024
1 parent 14b1723 commit 6255e7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/commands/hall_of_fame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { eq } from "drizzle-orm";
import { arrayAppend, arrayRemove } from "../db";
import { hallOfFameSettings } from "../db/schema";
import { hall_of_fame } from "../interactions";
import { AugmentedSubcommand, CommandHints, chatInputCommand, messageCommand, slashCommandMention, timestring } from "../utils/bot";
import { AugmentedSubcommand, CommandHints, YOUTUBE_REGEX, chatInputCommand, messageCommand, slashCommandMention, timestring } from "../utils/bot";
import { pluralize, ttry } from "../utils/general";

@ApplyOptions<Subcommand.Options>({
Expand Down Expand Up @@ -247,10 +247,14 @@ export class HallOfFameCommand extends AugmentedSubcommand {

const files: string[] = [];
const validAttachments = message.attachments.filter(this.canEmbedAttachment);
const matchesYoutube = message.content.match(YOUTUBE_REGEX);
if (validAttachments.size > 1) {
files.push(...message.attachments.map((a) => a.url));
} else if (validAttachments.size === 1) {
embed.setImage(validAttachments.first()!.url);
} else if (matchesYoutube) {
const [, id] = matchesYoutube;
embed.setImage(`https://img.youtube.com/vi/${id}/maxresdefault.jpg`);
}

const original = new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Original").setURL(message.url);
Expand Down
1 change: 1 addition & 0 deletions src/utils/bot/regex.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
export const VERIFY_REGEX = /(?<nick>.+?)\s?[|,\s]\s?(?<team>(?<vrc>(?<num>[0-9]{2,5})[A-Z]?)|(?<vexu>[A-Z]{2,5}[0-9]?)|([nN][oO] [tT][eE][aA][mM]))/;
export const YOUTUBE_REGEX = /(?:youtu\.be\/|youtube\.com\/(?:watch\?(?:.*&)?v=|(?:embed|v)\/))([^?&"'>]+)/;

0 comments on commit 6255e7e

Please sign in to comment.