-
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.
feat(bot): context menu commands + prettier configuration
- Loading branch information
1 parent
fb1d97a
commit b1b55cd
Showing
6 changed files
with
91 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none" | ||
} |
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,5 @@ | ||
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js'; | ||
|
||
export const convertUrlContextCommand = new ContextMenuCommandBuilder() | ||
.setName('Convert URL') | ||
.setType(ApplicationCommandType.Message); |
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,5 @@ | ||
import { convertUrlContextCommand } from './convertUrlContextCommand'; | ||
|
||
export const commands = { | ||
convertUrl: convertUrlContextCommand | ||
}; |
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,36 @@ | ||
import * as yup from 'yup'; | ||
import { isYoutubeOrSpotify } from '../../utils/isYoutubeOrSpotify'; | ||
import { convertUrl } from '../../api/convertUrl'; | ||
import { ActionRowBuilder, ButtonBuilder } from 'discord.js'; | ||
import { interactionButtons } from '../interactions'; | ||
|
||
export const processUrl = async (url: string) => { | ||
const isValid = yup | ||
.object() | ||
.shape({ | ||
url: yup.string().required().url() | ||
}) | ||
.isValidSync({ | ||
url | ||
}); | ||
|
||
if (!isValid) return; | ||
|
||
const urlMatchResult = isYoutubeOrSpotify(url); | ||
|
||
if (!urlMatchResult) return; | ||
|
||
const convertedUrl = await convertUrl(url); | ||
|
||
const type = urlMatchResult.type === 'spotify' ? 'youtube' : 'spotify'; | ||
const adjective = type === 'youtube' ? 'plebs' : 'gentlemen'; | ||
|
||
const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( | ||
...interactionButtons | ||
); | ||
|
||
return { | ||
content: `Here's a ${type} link for the ${adjective}:\n\n${convertedUrl}`, | ||
components: [buttons] | ||
}; | ||
}; |
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,16 @@ | ||
import { REST, Routes } from 'discord.js'; | ||
import { commands } from '../commands'; | ||
|
||
export const setupCommands = async (rest: REST, applicationId: string) => { | ||
console.log('Started refreshing application (/) commands.'); | ||
|
||
try { | ||
await rest.put(Routes.applicationCommands(applicationId), { | ||
body: Object.values(commands) | ||
}); | ||
|
||
console.log('Successfully reloaded application (/) commands.'); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; |