Skip to content

Commit

Permalink
Merge pull request #269 from patrickmonster:release/3.5.2
Browse files Browse the repository at this point in the history
Release. 3.5.2
  • Loading branch information
patrickmonster authored Jul 2, 2024
2 parents 8eeb4e3 + f4fa137 commit 458b2cc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"tabWidth": 4
},
"name": "discord-notification-ts",
"version": "3.5.1",
"version": "3.5.2",
"main": "index.js",
"repository": "https://github.com/patrickmonster/discord-notification-ts.git",
"author": "Soung jin Ryu <neocat@kakao.com>",
Expand Down
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
6 changes: 3 additions & 3 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 All @@ -216,7 +216,7 @@ export const sendMessageByChannels = async (channels: NoticeChannelHook[], isTes
if (!isTest && messages[0]) {
const { embeds } = messages[0].message;
openApi.post(`${process.env.WEB_HOOK_URL}`, {
content: `${channels.length}개 채널에 알림이 전송되었습니다.`,
content: `${channels[0].notice_id}]${channels.length}개 채널에 알림이 전송되었습니다.`,
embeds: embeds,
});
}
Expand Down
20 changes: 9 additions & 11 deletions src/controllers/component/noticeListQuerys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ ${tastTo('AND nt.use_yn = "Y"')}
// 알림 상세 (7 번은 라프텔)
const SelectNoticeDashbordByNoticeId = `
SELECT
JSON_OBJECT( 'name', IF( SUM(IF(nc.use_yn = 'Y', 1,0)) >= 1, '🔴','⚫')) AS emoji
, CAST(nc.notice_id AS CHAR) AS value
, IFNULL(nd.name, '지정되지 않음') AS label
, CONCAT(nd.message) AS description
JSON_OBJECT( 'name', IF( SUM(IF(nc.use_yn = 'Y', 1,0)) >= 1, '🔴','⚫')) AS emoji
, CAST(nc.notice_id AS CHAR) AS value
, IFNULL(n.name, '지정되지 않음') AS label
, CONCAT(n.message) AS description
FROM notice_channel nc
INNER JOIN notice n USING(notice_id)
INNER JOIN notice_detail nd using(notice_id)
WHERE notice_type = ?
INNER JOIN v_notice n USING(notice_id)
WHERE n.notice_type = ?
AND (guild_id = ? OR notice_type = 7)
GROUP BY nc.notice_id
`;
Expand All @@ -36,11 +35,10 @@ const SelectNoticeDashbordByGuildId = `
SELECT
JSON_OBJECT( 'name', IF( SUM(IF(nc.use_yn = 'Y', 1,0)) >= 1, '🔴','⚫')) AS emoji
, CAST(nc.notice_id AS CHAR) AS value
, IFNULL(nd.name, '지정되지 않음') AS label
, CONCAT(nd.message) AS description
, IFNULL(n.name, '지정되지 않음') AS label
, CONCAT(n.message) AS description
FROM notice_channel nc
INNER JOIN notice n USING(notice_id)
INNER JOIN notice_detail nd using(notice_id)
INNER JOIN v_notice n USING(notice_id)
WHERE (guild_id = ? OR notice_type = 7)
GROUP BY nc.notice_id
`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const selectPaging = async <E>(
page <= 0 ? 0 : page * size,
size,
]);
sqlLogger(query, [`${page} /${size}`, ...params], rows);
sqlLogger(query, params, [`${page} /${size}`, ...rows]);
const cnt = await connect
.query<({ total: number } & RowDataPacket)[]>(`SELECT COUNT(1) AS total FROM (\n${query}\n) A`, params)
.then(([[rows]]) => rows.total);
Expand Down

0 comments on commit 458b2cc

Please sign in to comment.