Skip to content

Commit

Permalink
Rewritten the /emote command
Browse files Browse the repository at this point in the history
  • Loading branch information
mxgic1337 committed Dec 19, 2023
1 parent 0356d2b commit 88d9a80
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 114 deletions.
Binary file modified .github/example1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Emote Cloner is **not affiliated** with Discord, Twitch, BetterTTV, FrankerFaceZ
- Clone this repository.
- Run `npm install` to install required dependencies.
- Create an application on [Discord Developer Portal](https://discord.com/developers/applications).
- Create file named `.env`, and add this information to it:
- Create file named `.env`, and add this to it:
```dotenv
CLIENT_ID= # Your app's client ID
TOKEN= # Your app's bot token
Expand Down
143 changes: 31 additions & 112 deletions commands/impl/EmoteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class EmoteCommand extends Command {
const name: string = nameOption !== null ? nameOption.value as string : emote.name
const disableAnimations = disableAnimationsOption !== null ? disableAnimationsOption.value as boolean : false

const animatedURL = emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === 'bttv' && sizeOption.value === '4x' ? '3x' : '4x' : '1x') + '.gif';
const animatedURL = emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === 'bttv' && sizeOption.value === '4x' ? '3x' : sizeOption.value as string : '2x') + '.gif';
const animatedFullURL = emote.hostURL.replace('{{size}}', platform === 'bttv' ? '3x' : '4x') + '.gif';
const staticURL = emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === 'bttv' && sizeOption.value === '4x' ? '3x' : '4x' : platform === 'bttv' ? '3x' : '4x') + '.webp';
const staticURL = emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === 'bttv' && sizeOption.value === '4x' ? '3x' : sizeOption.value as string : platform === 'bttv' ? '3x' : '4x') + '.webp';
const staticFullURL = emote.hostURL.replace('{{size}}', platform === 'bttv' ? '3x' : '4x') + '.webp';

let platformIcon: string;
Expand All @@ -53,138 +53,57 @@ export class EmoteCommand extends Command {
}

let embed = new EmbedBuilder()
.setTitle(`${emote.name} by ${emote.author.name}`)
.setAuthor({
url: undefined,
name: emote.author.name,
iconURL: emote.author.avatar
})
.setTitle(`${emote.name} by ${emote.author.name} (${platformText})`)
.setDescription('Uploading emote to Discord...')
.setThumbnail(emote.animated && !disableAnimations ? animatedFullURL : staticFullURL)
.setTimestamp()
.setFooter({
text: 'Added by ' + interaction.user.username,
iconURL: interaction.user.avatarURL() !== null ? '' + interaction.user.avatarURL() : interaction.user.defaultAvatarURL
text: `Executed by @${interaction.user.username}`
})
.setDescription(`Uploading emote to Discord...\nSelected size: \`${sizeOption !== null ? sizeOption.value : emote.animated && !disableAnimations ? '1x (Default)' : '4x (Default)'}\``)
.setColor('#333333')
.setColor('#262626')
.setFields([
{
name: 'State',
value: 'Uploading to Discord...',
inline: false,
name: 'Platform:',
value: `${platformIcon} ${platformText}`
},
{
name: 'Emote Name',
value: emote.name,
inline: true,
name: 'Selected size:',
value: sizeOption !== null ? sizeOption.value as string : 'Default'
},
{
name: 'Emote Author',
value: emote.author.name,
inline: true,
},
{
name: 'Animated?',
value: emote.animated ? `Yes${disableAnimations ? ' (Disabled)' : ''}` : 'No',
inline: true,
},
{
name: 'Platform',
value: `${platformIcon} ${platformText}`,
inline: true,
name: 'Animated:',
value: emote.animated ? disableAnimations ? 'No (Disabled)' : 'Yes' : 'No'
},
])
.setThumbnail(emote.animated ? animatedFullURL : staticFullURL)
interaction.reply({embeds: [embed]}).then(() => {
if (!interaction.guild) return;
if (emote === undefined) return;
interaction.guild.emojis.create({
attachment: emote.animated && !disableAnimations ?
animatedURL :
staticURL,
name: name
interaction.reply({embeds: [embed]}).then(()=>{
const guild = interaction.guild;
if (guild === null || emote === undefined) return;
console.log(`Uploading to Discord: ${emote.animated && !disableAnimations ? animatedURL : staticURL } ${guild.id}`)
guild.emojis.create({
attachment: emote.animated && !disableAnimations ? animatedURL : staticURL,
name: name,
reason: `@${interaction.user.username} used /emote`
}).then(emoji => {
console.error(`Uploaded emote in guild ${interaction.guildId}.`)
if (emote === undefined) return;
embed.setColor('#00ff59')
.setDescription(`Successfully added <${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}> **${emote.name}${name !== emote.name ? ` (${name})` : ''}** emote to Discord\nSelected size: \`${sizeOption !== null ? sizeOption.value : emote.animated && !disableAnimations ? '1x (Default)' : '4x (Default)'}\``)
.setFields([
{
name: 'State',
value: 'Done',
inline: false,
},
{
name: 'Emote Name',
value: emote.name,
inline: true,
},
{
name: 'Emote Author',
value: emote.author.name,
inline: true,
},
{
name: 'Animated?',
value: emote.animated ? `Yes${disableAnimations ? ' (Disabled)' : ''}` : 'No',
inline: true,
},
{
name: 'Platform',
value: `${platformIcon} ${platformText}`,
inline: true,
},
])
embed
.setDescription(`Emote ${emoji.toString()} **${emoji.name}** uploaded to Discord!`)
.setThumbnail(emote.animated && !disableAnimations ? animatedFullURL : staticFullURL)
.setColor('#00ff59')
interaction.editReply({embeds: [embed]})
}).catch(err => {
console.error(`Emote upload in guild ${interaction.guildId} failed: ${err.message}`)
if (emote === undefined) return;
embed.setDescription(`Selected size: \`${sizeOption !== null ? sizeOption.value : emote.animated && !disableAnimations ? '1x (Default)' : '4x (Default)'}\``)
.setColor('#ff2020')
.setFields([
{
name: 'State',
value: 'Failed',
inline: false,
},
{
name: 'Error Message',
value: '`' + errorMessage(err) + '`',
inline: false,
},
{
name: 'Emote Name',
value: emote.name,
inline: true,
},
{
name: 'Emote Author',
value: emote.author.name,
inline: true,
},
{
name: 'Animated?',
value: emote.animated ? `Yes${disableAnimations ? ' (Disabled)' : ''}` : 'No',
inline: true,
},
{
name: 'Platform',
value: `${platformIcon} ${platformText}`,
inline: true,
},
])
embed
.setDescription(`\`❌\` Upload failed:\n**\`${errorMessage(err)}\`**
\nReport bugs/issues on [GitHub](<https://github.com/mxgic1337/emote-cloner/issues>).`)
.setThumbnail(emote.animated && !disableAnimations ? animatedFullURL : staticFullURL)
.setColor('#ff2323')
interaction.editReply({embeds: [embed]})
})
}).catch(err => {
console.error(err)
const embed = new EmbedBuilder()
.setTitle("Error")
.setAuthor({
name: interaction.user.displayName,
iconURL: `https://cdn.discordapp.com/avatars/${interaction.user.id}/${interaction.user.avatar}.jpeg`
})
.setTimestamp()
.setColor('#ff2020')
.setDescription("`❌` Failed to send a status message.\nError: `"+err.message+"`")
interaction.reply({embeds: [embed]}).then().catch(console.error)
})

} else {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "emote-cloner",
"version": "1.1.3",
"version": "1.1.4",
"private": true,
"description": "Discord bot that clones BTTV/7TV emotes.",
"main": "dist/bot.js",
"scripts": {
Expand Down

0 comments on commit 88d9a80

Please sign in to comment.