Skip to content

Commit

Permalink
Merge pull request #78 from taichanNE30/fix-post-failed
Browse files Browse the repository at this point in the history
メンションへの反応を抑制するオプション
  • Loading branch information
tai-cha authored Jul 27, 2023
2 parents 96d8b8f + 27bdc03 commit 788a65a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pnpm
- Misskeyから取得したAPIのトークン
- 最低でもノートの作成・削除の権限は与えないと投稿が不可

### DATABASE_URL
### **DATABASE_URL**
- PostgreSQLのURL
- **返信機能を使うには必須**

Expand Down Expand Up @@ -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`は読み込まない)
Expand Down
13 changes: 13 additions & 0 deletions src/mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ 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 || ''
}

export const isDbEnabled = ():boolean => !!DATABASE_URL

export default {recordTime, postTitle, remindPostText, matcher, userName, server, isDbEnabled}
export default {recordTime, postTitle, remindPostText, matcher, userName, server, isDbEnabled, mention}

0 comments on commit 788a65a

Please sign in to comment.