Skip to content

Commit

Permalink
fix(discord): update embed on offline state
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Sep 9, 2022
1 parent 19b66ca commit c2d6505
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/integrations/discord.ts
Expand Up @@ -123,16 +123,16 @@ class Discord extends Integration {
.setURL('https://twitch.tv/' + broadcasterUsername)
.addFields(
this.fields
.filter((o) => this.filterFields(o))
.map((o) => this.prepareFields(o)))
.filter((o) => this.filterFields(o, isOnline))
.map((o) => this.prepareFields(o, isOnline)))
// Set the title of the field
.setTitle('https://twitch.tv/' + broadcasterUsername)
// Set the color of the embed
.setColor(color)
// Set the main content of the embed
.setDescription(description)
.setImage(`https://static-cdn.jtvnw.net/previews-ttv/live_user_${broadcasterUsername}-1920x1080.jpg?${Date.now()}`)
.setThumbnail(profileImageUrl)
.setThumbnail(isOnline ? profileImageUrl : null)
.setFooter({ text: prepare('integrations.discord.announced-by') + ' - https://www.sogebot.xyz' });
}

Expand Down Expand Up @@ -342,28 +342,38 @@ class Discord extends Integration {
this.embedMessageId = '';
}

filterFields(o: string) {
filterFields(o: string, isOnline: boolean) {
const broadcasterType = variables.get('services.twitch.broadcasterType') as string;

if (this.fieldsDisabled.includes(o)) {
return false;
}

if (!isOnline) {
if (['$viewers', '$followers', '$subscribers'].includes(o)) {
return false;
}
}

if (o === '$subscribers' && broadcasterType !== '') {
return false;
}
return true;
}

prepareFields(o: string) {
prepareFields(o: string, isOnline: boolean) {
if (o === '$game') {
return { name: prepare('webpanel.responses.variable.game'), value: stats.value.currentGame ?? '' };
}
if (o === '$title') {
return { name: prepare('webpanel.responses.variable.title'), value: stats.value.currentTitle ?? '' };
}
if (o === '$startedAt') {
return { name: prepare('integrations.discord.started-at'), value: this.embedStartedAt, inline: true };
if (isOnline) {
return { name: prepare('integrations.discord.started-at'), value: this.embedStartedAt, inline: true };
} else {
return { name: prepare('integrations.discord.streamed-at'), value: `${this.embedStartedAt} - ${dayjs().tz(timezone).format('LLL')}`, inline: true };
}
}
if (o === '$viewers') {
return { name: prepare('webpanel.viewers'), value: String(stats.value.currentViewers), inline: true };
Expand Down

0 comments on commit c2d6505

Please sign in to comment.