Skip to content

Commit

Permalink
feat: 埋め込みカラーをパーソナルカラーに (#679)
Browse files Browse the repository at this point in the history
* feat: add personal color constant

* feat: change embed color option

* feat: change reply embed color option

* fix: change function

* fix(ci): remove test case color option

* fix: percolation import
  • Loading branch information
m2en authored Jan 19, 2023
1 parent b6aeaad commit 9329ec9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 44 deletions.
36 changes: 3 additions & 33 deletions src/adaptor/discord/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChannelType, type Client, EmbedBuilder } from 'discord.js';
import { ChannelType, type Client } from 'discord.js';
import type { EmbedMessage } from '../../model/embed-message.js';
import type { StandardOutput } from '../../service/output.js';
import { convertEmbed } from '../embed-convert.js';

export class DiscordOutput implements StandardOutput {
constructor(
Expand All @@ -14,40 +15,9 @@ export class DiscordOutput implements StandardOutput {
throw new Error(`the channel (${this.channelId}) is not text channel`);
}

const made = buildEmbed(embed);
const made = convertEmbed(embed);
await channel.send({
embeds: [made]
});
}
}

function buildEmbed(embed: EmbedMessage) {
const makeEmbed = new EmbedBuilder();
const { title, color, description, fields, url, footer, thumbnail, author } =
embed;
if (author) {
makeEmbed.setAuthor({ name: author.name, iconURL: author.iconUrl });
}
if (color) {
makeEmbed.setColor(color);
}
if (description) {
makeEmbed.setDescription(description);
}
if (fields) {
makeEmbed.setFields(fields);
}
if (footer) {
makeEmbed.setFooter({ text: footer });
}
if (title) {
makeEmbed.setTitle(title);
}
if (url) {
makeEmbed.setURL(url);
}
if (thumbnail) {
makeEmbed.setThumbnail(thumbnail.url);
}
return makeEmbed;
}
12 changes: 7 additions & 5 deletions src/adaptor/embed-convert.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { EmbedBuilder } from 'discord.js';
import type { EmbedMessage } from '../model/embed-message.js';

// はらちょのパーソナルカラー
// https://github.com/approvers/OreOreBot2/issues/675
export const PERSONAL_COLOR = 0x00b7c4;

export const convertEmbed = ({
author,
color,
description,
fields,
footer,
title,
thumbnail,
url
url,
color
}: EmbedMessage): EmbedBuilder => {
const embed = new EmbedBuilder();
if (author) {
Expand All @@ -19,9 +23,6 @@ export const convertEmbed = ({
iconURL: author.iconUrl
});
}
if (color) {
embed.setColor(color);
}
if (description) {
embed.setDescription(description);
}
Expand All @@ -42,5 +43,6 @@ export const convertEmbed = ({
if (url) {
embed.setURL(url);
}
embed.setColor(color ?? PERSONAL_COLOR);
return embed;
};
3 changes: 1 addition & 2 deletions src/service/command/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export class PingCommand implements CommandResponder<typeof SCHEMA> {
await message.reply({
title: 'Ping',
url: 'https://discordstatus.com/',
description: `🏓 Pongだよ。 / **${this.ping.avgPing}**ms`,
color: 0x7ec4ed
description: `🏓 Pongだよ。 / **${this.ping.avgPing}**ms`
});
}
}
2 changes: 0 additions & 2 deletions src/service/voice-diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ it('use case of VoiceDiff', async () => {
expect(message).toStrictEqual({
title: 'めるが限界に入りました',
description: '何かが始まる予感がする。',
color: 0x1e63e9,
author: { name: 'はらちょからのお知らせ' },
thumbnail: {
url: 'https://cdn.discordapp.com/avatars/586824421470109716/9eb541e567f0ce82d34e55a37213c524.webp'
Expand All @@ -22,7 +21,6 @@ it('use case of VoiceDiff', async () => {
expect(message).toStrictEqual({
title: 'めるが限界から抜けました',
description: 'あいつは良い奴だったよ...',
color: 0x1e63e9,
author: { name: 'はらちょからのお知らせ' },
thumbnail: {
url: 'https://cdn.discordapp.com/avatars/586824421470109716/9eb541e567f0ce82d34e55a37213c524.webp'
Expand Down
2 changes: 0 additions & 2 deletions src/service/voice-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class VoiceDiff
await this.stdout.sendEmbed({
title: userName + 'が' + channelName + 'に入りました',
description: '何かが始まる予感がする。',
color: 0x1e63e9,
author: { name: 'はらちょからのお知らせ' },
thumbnail: { url: userAvatar }
});
Expand All @@ -36,7 +35,6 @@ export class VoiceDiff
await this.stdout.sendEmbed({
title: userName + 'が' + channelName + 'から抜けました',
description: 'あいつは良い奴だったよ...',
color: 0x1e63e9,
author: { name: 'はらちょからのお知らせ' },
thumbnail: { url: userAvatar }
});
Expand Down

0 comments on commit 9329ec9

Please sign in to comment.