-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from t1nyb0x/develop
Webhook通知処理追加
- Loading branch information
Showing
7 changed files
with
124 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { getUserName } from './utils/getUserName'; | ||
|
||
export default async function abuseReportResolved(body: any, webhookUrl: string) { | ||
const targetUserName = await getUserName(body.server, body.body.targetUserId); | ||
const reporterUserName = await getUserName(body.server, body.body.reporterId); | ||
const asigneeUserName = await getUserName(body.server, body.body.assigneeId); | ||
|
||
const isOk = await fetch(webhookUrl, { | ||
body: JSON.stringify({ | ||
embeds: [ | ||
{ | ||
title: '通報を解決しました', | ||
color: 3359727, | ||
description: `通報が解決されました。\n### 通報内容\n ${body.body.comment}\n### 通報があったサーバー\n${body.server}`, | ||
fields: [ | ||
{ | ||
name: '通報されたユーザー', | ||
value: `[${targetUserName}](${body.server}/users/${body.body.targetUserId})`, | ||
inline: true, | ||
}, | ||
{ | ||
name: '通報を行ったユーザー', | ||
value: `[${reporterUserName}](${body.server}/users/${body.body.reporterId})`, | ||
inline: true, | ||
}, | ||
{ | ||
name: '通報を解決したユーザー', | ||
value: `[${asigneeUserName}](${body.server}/users/${body.body.assigneeId})`, | ||
inline: true, | ||
}, | ||
], | ||
}, | ||
], | ||
}), | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}).then((res) => res.ok); | ||
|
||
return isOk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default async function inactiveModeratorsInvitationOnlyChanged(body: any, webhookUrl: string) { | ||
const isOk = await fetch(webhookUrl, { | ||
body: JSON.stringify({ | ||
embeds: [ | ||
{ | ||
title: '新規登録が招待制に移行されました', | ||
color: 15409955, | ||
description: `### 注意\nモデレーターのアクティブが一定期間なかったため、新規登録が招待制に移行しました。\n新規登録を開放したい場合は管理設定から変更してください。\n### 対象サーバー\n${body.server}`, | ||
}, | ||
], | ||
}), | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}).then((res) => res.ok); | ||
|
||
return isOk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default async function inactiveModeratorsWarning(body: any, webhookUrl: string) { | ||
const isOk = await fetch(webhookUrl, { | ||
body: JSON.stringify({ | ||
embeds: [ | ||
{ | ||
title: 'まもなく新規登録が招待制へ移行します', | ||
color: 14931798, | ||
description: `### 注意\nモデレーターのアクティブが一定期間なかったため、まもなく新規登録が招待制へ移行します。\nモデレーターがログインすることで、この自動処理は中止されます。\n### 対象サーバー\n${body.server}`, | ||
}, | ||
], | ||
}), | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}).then((res) => res.ok); | ||
|
||
return isOk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export async function getUserName(server: string, userId: string): Promise<string> { | ||
// set body | ||
const requestBodySchema = { | ||
userId: userId, | ||
}; | ||
|
||
const init = { | ||
body: JSON.stringify(requestBodySchema), | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json;charset=UTF-8', | ||
}, | ||
}; | ||
|
||
const response = await fetch(server + '/api/users/show', init); | ||
const userData = await response.text(); | ||
const userName = JSON.parse(userData).username; | ||
|
||
return userName; | ||
} |