diff --git a/README.md b/README.md index a84dc77..5624754 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ pnpm - Misskeyから取得したAPIのトークン - 最低でもノートの作成・削除の権限は与えないと投稿が不可 -### DATABASE_URL +### **DATABASE_URL** - PostgreSQLのURL - **返信機能を使うには必須** @@ -84,6 +84,20 @@ pnpm - 値を`TRUE`に設定するとMisskeyにノートが投稿されなくなります - 手元で集計のみ行いたい場合等にお使いください +### DISABLE_MENTION_AROUND_TIME +- 値を`TRUE`に設定すると集計時刻の前後でのメンションに反応しないようにすることが可能です +- default FALSE + +### DISABLE_MENTION_SEC_BEFORE +- DISABLE_MENTION_AROUND_TIME と併用して使うオプションです +- メンションに反応しない時間を設定する際に集計時刻の**何ミリ秒前から**反応しないかを設定可能です +- default 60000 + +### DISABLE_MENTION_SEC_AFTER +- DISABLE_MENTION_AROUND_TIME と併用して使うオプションです +- メンションに反応しない時間を設定する際に集計時刻の**何ミリ秒後まで**反応しないかを設定可能です +- default 60000 + ## etc.. - dotenv導入済みなのでローカルなどで試す場合は`.env`のファイルを用意して配置すれば設定変更可能 - 開発環境(NODE_ENV=development)の場合は`.env.development`が読み込まれる(`.env`は読み込まない) diff --git a/src/mentions.ts b/src/mentions.ts index c1e2053..a4115d7 100644 --- a/src/mentions.ts +++ b/src/mentions.ts @@ -66,6 +66,19 @@ const getStatics = async (u:Misskey.entities.User) => { const stream = new Misskey.Stream(Config.server.origin, { token: Config.server.credential }, { WebSocket }) const mainChannel = stream.useChannel('main') mainChannel.on('mention', async note => { + + // OPTION メンション抑制 レートリミットの影響を軽減可能 + if (Config.mention.disable_around_time) { + const now = Date.now() + let [before, after] = [Config.mention.disable_sec_before, Config.mention.disable_sec_after] + // beforeより後,afterより前の場合,スキップ + if ((Config.recordTime.getTime() - before) < now && now < (Config.recordTime.getTime() - after) ) { + // NOTE: リアクション送ろうとも思ったけど反応したら結局レートリミット引っかかるじゃん + // 集計開始ノートで告知すればよくない? + return // await YAMAG.Misskey.request('notes/reactions/create', { noteId: note.id, reaction: "😥" }) + } + } + if (isUserDetailed(note.user) && note.user?.isBot === false) { if (note.userId === note.reply?.userId) { if(note.reply?.text?.match(Config.matcher)) { diff --git a/src/utils/config.ts b/src/utils/config.ts index 45ffabb..5da8d6c 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -18,6 +18,12 @@ export const userName = process.env?.USER_NAME || "334_t" export const matcher = process.env.MATCHER || /(33-?4|:hanshin:)/ const DATABASE_URL = process.env.DATABASE_URL +export const mention = { + disable_around_time: process.env?.DISABLE_MENTION_AROUND_TIME === 'TRUE', + disable_sec_before: parseInt(process.env.DISABLE_MENTION_SEC_BEFORE || '') || 60000, + disable_sec_after: parseInt(process.env.DISABLE_MENTION_SEC_AFTER || '') || 60000 +} + export const server:Server = { origin: process.env?.SERVER_ORIGIN || "https://misskey.io", credential: process.env.SERVER_TOKEN || '' @@ -25,4 +31,4 @@ export const server:Server = { export const isDbEnabled = ():boolean => !!DATABASE_URL -export default {recordTime, postTitle, remindPostText, matcher, userName, server, isDbEnabled} \ No newline at end of file +export default {recordTime, postTitle, remindPostText, matcher, userName, server, isDbEnabled, mention} \ No newline at end of file