Skip to content

Commit

Permalink
Add: slack notification about detecting result
Browse files Browse the repository at this point in the history
  • Loading branch information
kmc7468 committed Feb 22, 2024
1 parent bf6b7ce commit af808fb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
48 changes: 45 additions & 3 deletions src/lottery/modules/slackNotification.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
const { sendTextToReportChannel } = require("../../modules/slackNotification");

const generateContent = (name, userIds, roomIds = []) => {
if (userIds.length === 0) return "";

const strUserIds = userIds.join(", ");
const strRoomIds =
roomIds.length > 0 ? ` (관련된 방: ${roomIds.join(", ")})` : "";
return `\n${name}: ${strUserIds}${strRoomIds}`;
};

const notifyAbuseDetectionResultToReportChannel = (
abusingUsers,
reports,
abusingUserIds,
reportedUserIds,
rooms,
multiplePartUserIds,
lessChatRooms,
lessChatUserIds
) => {
// TODO
const title = `어제의 활동을 기준으로, ${abusingUserIds.length}명의 어뷰징 의심 사용자를 감지하였습니다.`;

if (abusingUserIds.length === 0) {
sendTextToReportChannel(title);
return;
}

const strAbusingUsers = generateContent(
"전체 어뷰징 의심 사용자",
abusingUserIds
);
const strReportedUsers = generateContent(
'"기타 사유"로 신고받은 사용자',
reportedUserIds
);
const strMultiplePartUsers = generateContent(
"하루에 탑승 기록이 많은 사용자",
multiplePartUserIds,
rooms.reduce((array, { roomIds }) => array.concat(roomIds), [])
);
const strLessChatUsers = generateContent(
"채팅 개수가 5개 미만인 방에 속한 사용자",
lessChatUserIds,
lessChatRooms.reduce(
(array, room) => (room ? array.concat([room.roomId]) : array),
[]
)
);
const contents = strAbusingUsers.concat(
strReportedUsers,
strMultiplePartUsers,
strLessChatUsers
);

sendTextToReportChannel(`${title}\n${contents}`);
};

module.exports = {
Expand Down
12 changes: 6 additions & 6 deletions src/lottery/schedules/detectAbusingUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module.exports = async () => {
const candidateUserIds = candidateUsers.map((user) => user.userId);

// 기준 1 ~ 기준 3에 각각 해당되는 사용자 목록
const { reports, reportedUserIds } = await detectReportedUsers(
const { reportedUserIds } = await detectReportedUsers(
period,
candidateUserIds
);
Expand All @@ -197,25 +197,25 @@ module.exports = async () => {
);

// 기준 1 ~ 기준 3 중 하나라도 해당되는 사용자 목록
const abusingUsers = removeObjectIdDuplicates(
const abusingUserIds = removeObjectIdDuplicates(
reportedUserIds.concat(multiplePartUserIds, lessChatUserIds)
);

logger.info("Abusing user detection successfully finished");
logger.info(
`Total ${abusingUsers.length} users detected! Refer to Slack for more information`
`Total ${abusingUserIds.length} users detected! Refer to Slack for more information`
);

// Slack으로 알림 전송
notifyAbuseDetectionResultToReportChannel(
abusingUsers,
reports,
abusingUserIds,
reportedUserIds,
rooms,
multiplePartUserIds,
lessChatRooms,
lessChatUserIds
);

logger.info("Abusing user detection successfully finished");
} catch (err) {
logger.error(err);
logger.error("Abusing user detection failed");
Expand Down

0 comments on commit af808fb

Please sign in to comment.