Skip to content

Commit

Permalink
Add. 훅알림 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmonster committed Jul 2, 2024
1 parent c71be78 commit f4fa137
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ export const channelCreate = async (guild_id: string, data: RESTPostAPIGuildChan
};

export const messageCreate = async (channel_id: string, body: RESTPostAPIChannelMessageJSONBody) =>
postDiscord<RESTPostAPIChannelMessageResult>(`/channels/${channel_id}/messages`, { body }).then(async res => {
await postDiscordMessage(`/channels/${channel_id}/messages`, body);

export const messageHookCreate = async (hook_id: string, token: string, body: RESTPostAPIWebhookWithTokenJSONBody) =>
await postDiscordMessage(`/${hook_id}/${token}`, body);

export const postDiscordMessage = async (url: `/${string}`, body: RESTPostAPIChannelMessageJSONBody) =>
await postDiscord<RESTPostAPIChannelMessageResult>(url, { body }).then(async res => {
CreateMessage({
channel_id,
channel_id: res.channel_id,
message_id: res.id,
message: JSON.stringify(body),
}).catch(() => {});

return res;
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import createCalender from 'utils/createCalender';
import discord, { openApi } from 'utils/discordApiInstance';
import { ParseInt, convertMessage } from 'utils/object';
import { catchRedis } from 'utils/redis';
import { getUser, messageCreate } from './discord';
import { getUser, messageCreate, postDiscordMessage } from './discord';

const ERROR = (...e: any) => {
console.error(__filename, ' Error: ', ...e);
Expand Down Expand Up @@ -192,7 +192,7 @@ export const sendMessageByChannels = async (channels: NoticeChannelHook[], isTes
break;
case ChannelMessageType.WEBHOOK:
// 훅 발송
originMessage = await openApi.post<APIMessage>(`/${url}`, message).catch(e => {
originMessage = await postDiscordMessage(`/${url}`, message).catch(e => {
ERROR(e);
if ([10003].includes(e.code)) {
deleteNoticeChannel(notice_id, channel_id).catch(e => {
Expand Down

0 comments on commit f4fa137

Please sign in to comment.