Skip to content

Commit

Permalink
Added better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mxgic1337 committed Nov 23, 2023
1 parent ec3d882 commit 0356d2b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build Check
on:
push:
branches:
- 'main'
pull_request:
types:
- opened
- reopened
jobs:
check-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '21'
- run: npm install
- run: npm run build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Emote Cloner
**Emote Cloner** is a Discord bot that clones emotes from BetterTTV and 7TV into Discord.

Emote Cloner is **not affiliated** with Twitch, BetterTTV, FrankerFaceZ or 7TV.
Emote Cloner is **not affiliated** with Discord, Twitch, BetterTTV, FrankerFaceZ or 7TV.

## 🔗 Links
- [🤖 Invite Link](https://discord.com/api/oauth2/authorize?client_id=1163079809719611413&permissions=8799314249792&scope=bot)
Expand Down
16 changes: 9 additions & 7 deletions bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Client, GatewayIntentBits} from "discord.js";
import {Client, GatewayIntentBits, ActivityType} from "discord.js";
import dotenv from 'dotenv'
import {commandList, registerCommands} from "./commands/commands";
import {EmoteCommand} from "./commands/impl/EmoteCommand";
Expand All @@ -13,12 +13,14 @@ client.on('ready', (c)=>{
registerCommands().then()
commandList.push(new EmoteCommand())
console.log(`Bot is ready. Logged in as ${c.user.tag}`)
c.user.setPresence({
status: 'online',
activities: [
{name: '/emote'}
]
})
setInterval(()=>{
c.user.setPresence({
status: 'online',
activities: [
{name: `/emote`, type: ActivityType.Watching, state: `Cloning emotes on ${c.guilds.cache.size} servers! ✨`},
],
})
}, 60000)
})

client.on('interactionCreate', (interaction)=>{
Expand Down
40 changes: 11 additions & 29 deletions commands/impl/EmoteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class EmoteCommand extends Command {
break;
}

const embed = new EmbedBuilder()
let embed = new EmbedBuilder()
.setTitle(`${emote.name} by ${emote.author.name}`)
.setAuthor({
name: emote.author.name,
Expand Down Expand Up @@ -92,7 +92,7 @@ export class EmoteCommand extends Command {
inline: true,
},
])
.setThumbnail(emote.animated ? emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === "bttv" && (sizeOption.value as string) === "4x" ? "3x" : sizeOption.value as string : '4x.gif') : emote.hostURL.replace('{{size}}', sizeOption !== null ? platform === "bttv" && (sizeOption.value as string) === "4x" ? "3x" : sizeOption.value as string : platform === 'bttv' ? '3x.webp' : '4x.webp'))
.setThumbnail(emote.animated ? animatedFullURL : staticFullURL)
interaction.reply({embeds: [embed]}).then(() => {
if (!interaction.guild) return;
if (emote === undefined) return;
Expand All @@ -104,18 +104,7 @@ export class EmoteCommand extends Command {
}).then(emoji => {
console.error(`Uploaded emote in guild ${interaction.guildId}.`)
if (emote === undefined) return;
const embed = new EmbedBuilder()
.setTitle(`${emote.name} by ${emote.author.name}`)
.setAuthor({
name: emote.author.name,
iconURL: emote.author.avatar
})
.setFooter({
text: 'Added by ' + interaction.user.username,
iconURL: interaction.user.avatarURL() !== null ? '' + interaction.user.avatarURL() : interaction.user.defaultAvatarURL
})
.setTimestamp()
.setColor('#00ff59')
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([
{
Expand Down Expand Up @@ -144,23 +133,11 @@ export class EmoteCommand extends Command {
inline: true,
},
])
.setThumbnail(emote.animated ? animatedFullURL : staticFullURL)
interaction.editReply({embeds: [embed]})
}).catch(err => {
console.error(`Emote upload in guild ${interaction.guildId} failed: ${err.message}`)
if (emote === undefined) return;
const embed = new EmbedBuilder()
.setTitle(`${emote.name} by ${emote.author.name}`)
.setAuthor({
name: emote.author.name,
iconURL: emote.author.avatar
})
.setDescription(`Selected size: \`${sizeOption !== null ? sizeOption.value : emote.animated && !disableAnimations ? '1x (Default)' : '4x (Default)'}\``)
.setTimestamp()
.setFooter({
text: 'Added by ' + interaction.user.username,
iconURL: interaction.user.avatarURL() !== null ? '' + interaction.user.avatarURL() : interaction.user.defaultAvatarURL
})
embed.setDescription(`Selected size: \`${sizeOption !== null ? sizeOption.value : emote.animated && !disableAnimations ? '1x (Default)' : '4x (Default)'}\``)
.setColor('#ff2020')
.setFields([
{
Expand All @@ -170,7 +147,7 @@ export class EmoteCommand extends Command {
},
{
name: 'Error Message',
value: '`' + err.message + '`',
value: '`' + errorMessage(err) + '`',
inline: false,
},
{
Expand All @@ -194,7 +171,6 @@ export class EmoteCommand extends Command {
inline: true,
},
])
.setThumbnail(emote.animated ? animatedFullURL : staticFullURL)
interaction.editReply({embeds: [embed]})
})
}).catch(err => {
Expand Down Expand Up @@ -225,4 +201,10 @@ export class EmoteCommand extends Command {
}
});
}
}

function errorMessage(err: Error) {
if (err.message.includes("Asset exceeds maximum size:") || err.message.includes("Failed to resize asset below the maximum size:")) {return "Emote is too big."}
else if (err.message.includes("name[STRING_TYPE_REGEX]")) {return "Emote name is invalid."}
else return err.message
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emote-cloner",
"version": "1.1.2",
"version": "1.1.3",
"description": "Discord bot that clones BTTV/7TV emotes.",
"main": "dist/bot.js",
"scripts": {
Expand Down

0 comments on commit 0356d2b

Please sign in to comment.