cleanup music search + actually compile subdirectories with tsc 😭
This commit is contained in:
parent
bdec64a050
commit
f76984fa7d
16 changed files with 63 additions and 55 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
/.pnp
|
/.pnp
|
||||||
|
src/**/*.js
|
||||||
.pnp.js
|
.pnp.js
|
||||||
|
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { ApplicationCommandType, type AutocompleteFocusedOption, AutocompleteInteraction, ChatInputCommandInteraction, ContextMenuCommandBuilder, ContextMenuCommandInteraction, Message, SharedSlashCommand, User } from "discord.js";
|
import { ApplicationCommandType, type AutocompleteFocusedOption, AutocompleteInteraction, ChatInputCommandInteraction, ContextMenuCommandBuilder, ContextMenuCommandInteraction, Message, SharedSlashCommand, User } from "discord.js";
|
||||||
import { type Config } from "./config";
|
import { type Config } from "./config.ts";
|
||||||
|
|
||||||
export abstract class ICommand { }
|
export abstract class ICommand { }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,12 @@ import {
|
||||||
ApplicationCommandType,
|
ApplicationCommandType,
|
||||||
ContextMenuCommandBuilder,
|
ContextMenuCommandBuilder,
|
||||||
ContextMenuCommandInteraction, escapeCodeBlock,
|
ContextMenuCommandInteraction, escapeCodeBlock,
|
||||||
InteractionContextType,
|
|
||||||
Message,
|
Message,
|
||||||
Snowflake,
|
type UserResolvable
|
||||||
User, UserResolvable
|
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { parse as acornParse } from 'acorn'
|
import { parse as acornParse } from 'acorn'
|
||||||
import { ContextCommand } from "../command.ts";
|
import { ContextCommand } from "../command.ts";
|
||||||
import {ModuleDeclaration, Statement} from "acorn";
|
import {type ModuleDeclaration,type Statement} from "acorn";
|
||||||
import {generate} from "astring";
|
import {generate} from "astring";
|
||||||
import {inspect} from "node:util";
|
import {inspect} from "node:util";
|
||||||
|
|
||||||
|
|
@ -130,4 +128,4 @@ export default class Mock extends ContextCommand<Message> {
|
||||||
await interaction.editReply('```js\n' + escapeCodeBlock(inspect(result)) + "\n```")
|
await interaction.editReply('```js\n' + escapeCodeBlock(inspect(result)) + "\n```")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {Command} from "../command.ts";
|
import {Command} from "../command.ts";
|
||||||
import {
|
import {
|
||||||
ApplicationIntegrationType, AutocompleteFocusedOption, AutocompleteInteraction,
|
ApplicationIntegrationType, type AutocompleteFocusedOption, AutocompleteInteraction,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
InteractionContextType, RESTGetAPIApplicationEmojisResult, Routes,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { config, Config } from "../config.ts";
|
import { config, type Config } from "../config.ts";
|
||||||
|
|
||||||
export default class FediemojiCommand extends Command {
|
export default class FediemojiCommand extends Command {
|
||||||
async getSharkeyEmojis() {
|
async getSharkeyEmojis() {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,7 @@ import {
|
||||||
ApplicationCommandType,
|
ApplicationCommandType,
|
||||||
ContextMenuCommandBuilder,
|
ContextMenuCommandBuilder,
|
||||||
ContextMenuCommandInteraction,
|
ContextMenuCommandInteraction,
|
||||||
InteractionContextType,
|
Message} from "discord.js";
|
||||||
Message,
|
|
||||||
Snowflake,
|
|
||||||
User
|
|
||||||
} from "discord.js";
|
|
||||||
import { ContextCommand } from "../command.ts";
|
import { ContextCommand } from "../command.ts";
|
||||||
|
|
||||||
export default class Mock extends ContextCommand<Message> {
|
export default class Mock extends ContextCommand<Message> {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {Command} from "../command.ts";
|
import {Command} from "../command.ts";
|
||||||
|
import {chunkArray} from '../util.ts';
|
||||||
import {
|
import {
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
ApplicationIntegrationType, ButtonBuilder, ButtonStyle,
|
ApplicationIntegrationType, ButtonBuilder, ButtonStyle,
|
||||||
|
|
@ -6,8 +7,21 @@ import {
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts";
|
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts";
|
||||||
|
import * as z from 'zod';
|
||||||
|
|
||||||
|
const itunesResponseShape = z.object({
|
||||||
|
results: z.array(z.object({
|
||||||
|
artistId: z.number(),
|
||||||
|
artistName: z.string(),
|
||||||
|
trackViewUrl: z.string(),
|
||||||
|
trackName: z.string(),
|
||||||
|
collectionName: z.string(),
|
||||||
|
collectionCensoredName: z.string().optional(),
|
||||||
|
censoredTrackName: z.string().optional(),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
export default class PingCommand extends Command {
|
export default class PingCommand extends Command {
|
||||||
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
||||||
|
|
@ -15,8 +29,11 @@ export default class PingCommand extends Command {
|
||||||
const search = interaction.options.getString("search")!
|
const search = interaction.options.getString("search")!
|
||||||
const paramsObj = {entity: "song", term: search};
|
const paramsObj = {entity: "song", term: search};
|
||||||
const searchParams = new URLSearchParams(paramsObj);
|
const searchParams = new URLSearchParams(paramsObj);
|
||||||
const itunesinfo = (await (await fetch(`https://itunes.apple.com/search?${searchParams.toString()}`)).json()).results[0];
|
const itunesResponse = await fetch(`https://itunes.apple.com/search?${searchParams.toString()}`);
|
||||||
const link = itunesinfo.trackViewUrl
|
const itunesJson = await itunesResponse.json();
|
||||||
|
const itunesinfo = itunesResponseShape.parse(itunesJson);
|
||||||
|
const itunesSong = itunesinfo.results[0];
|
||||||
|
const link = itunesSong.trackViewUrl
|
||||||
const songlink = await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json())
|
const songlink = await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json())
|
||||||
const preferredApi = getSongOnPreferredProvider(songlink, link)!
|
const preferredApi = getSongOnPreferredProvider(songlink, link)!
|
||||||
|
|
||||||
|
|
@ -29,30 +46,18 @@ export default class PingCommand extends Command {
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: "amy jr",
|
text: "amy jr",
|
||||||
});
|
});
|
||||||
const meow = Object.keys(songlink.linksByPlatform)
|
const platforms = Object.keys(songlink.linksByPlatform)
|
||||||
let message = ""
|
const buttons = platforms.map(platform =>
|
||||||
|
new ButtonBuilder()
|
||||||
const nya: ActionRowBuilder<ButtonBuilder>[] = [];
|
.setURL(songlink.linksByPlatform[platform].url)
|
||||||
let currentRow = new ActionRowBuilder<ButtonBuilder>();
|
.setLabel(kyzaify(platform))
|
||||||
|
.setStyle(ButtonStyle.Link));
|
||||||
for (const meowi of meow) {
|
const chunkedButtons = chunkArray(buttons, 5);
|
||||||
if (currentRow.components.length >= 5) {
|
const rows = chunkedButtons.map(rowButtons =>
|
||||||
nya.push(currentRow);
|
new ActionRowBuilder<ButtonBuilder>().addComponents(...rowButtons));
|
||||||
currentRow = new ActionRowBuilder<ButtonBuilder>();
|
|
||||||
}
|
|
||||||
currentRow.addComponents(
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setURL(songlink.linksByPlatform[meowi].url)
|
|
||||||
.setLabel(kyzaify(meowi))
|
|
||||||
.setStyle(ButtonStyle.Link)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (currentRow.components.length > 0) {
|
|
||||||
nya.push(currentRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
components: nya,
|
components: rows,
|
||||||
embeds: [embed]
|
embeds: [embed]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
|
||||||
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts"
|
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts"
|
||||||
import {Config} from "../config.ts";
|
import {type Config} from "../config.ts";
|
||||||
|
|
||||||
function keepV(url: string): string {
|
function keepV(url: string): string {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import {
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
import sharp, { SharpInput } from "sharp";
|
import sharp, { type SharpInput } from "sharp";
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { Canvas, loadImage } from "canvas";
|
import { Canvas, loadImage } from "canvas";
|
||||||
import { readdir, readFile } from "fs/promises";
|
import { readdir, readFile } from "fs/promises";
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
|
|
||||||
export default class PingCommand extends Command {
|
export default class PingCommand extends Command {
|
||||||
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import {
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts";
|
import {getSongOnPreferredProvider, kyzaify} from "../helper.ts";
|
||||||
|
|
||||||
export default class MusicInfoCommand extends Command {
|
export default class MusicInfoCommand extends Command {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import {
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Config } from "../config.ts";
|
import { type Config } from "../config.ts";
|
||||||
|
|
||||||
export default class PingCommand extends Command {
|
export default class PingCommand extends Command {
|
||||||
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
InteractionContextType, Routes,
|
InteractionContextType, Routes,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import {Config} from "../config.ts";
|
import {type Config} from "../config.ts";
|
||||||
|
|
||||||
|
|
||||||
export default class StealEmojiCommand extends Command {
|
export default class StealEmojiCommand extends Command {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { Command } from "../command.ts";
|
import { Command } from "../command.ts";
|
||||||
import {
|
import {
|
||||||
ApplicationIntegrationType,
|
ApplicationIntegrationType,
|
||||||
AutocompleteFocusedOption,
|
type AutocompleteFocusedOption,
|
||||||
AutocompleteInteraction,
|
AutocompleteInteraction,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
InteractionContextType, REST, RESTGetAPIApplicationEmojisResult, Routes,
|
InteractionContextType,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { config, Config } from "../config.ts";
|
import type { Config } from "../config.ts";
|
||||||
|
|
||||||
export default class SuperFakeNitroCommand extends Command {
|
export default class SuperFakeNitroCommand extends Command {
|
||||||
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,7 @@ import {
|
||||||
ApplicationCommandType,
|
ApplicationCommandType,
|
||||||
ContextMenuCommandBuilder,
|
ContextMenuCommandBuilder,
|
||||||
ContextMenuCommandInteraction,
|
ContextMenuCommandInteraction,
|
||||||
InteractionContextType,
|
Message} from "discord.js";
|
||||||
Message,
|
|
||||||
Snowflake,
|
|
||||||
User
|
|
||||||
} from "discord.js";
|
|
||||||
import { ContextCommand } from "../command.ts";
|
import { ContextCommand } from "../command.ts";
|
||||||
|
|
||||||
export default class Uwuifier extends ContextCommand<Message> {
|
export default class Uwuifier extends ContextCommand<Message> {
|
||||||
|
|
|
||||||
12
src/util.ts
Normal file
12
src/util.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
export function chunkArray<T>(
|
||||||
|
array: T[],
|
||||||
|
chunkSize: number
|
||||||
|
): T[][] {
|
||||||
|
const b: T[][] = []
|
||||||
|
array.forEach(element =>
|
||||||
|
b && b[b.length - 1] && b[b.length - 1].length < chunkSize
|
||||||
|
? b[b.length - 1].push(element)
|
||||||
|
: b.push([element])
|
||||||
|
)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
@ -17,5 +17,5 @@
|
||||||
"module": "ESNext"
|
"module": "ESNext"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src/*"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue