Skip to content

Commit 90e583b

Browse files
u1-liquidkakkokari-gtyih
authored andcommitted
enhance(antenna): Botの投稿を除外できるように (MisskeyIO#545)
(cherry picked from commit a95ce06)
1 parent 7795045 commit 90e583b

File tree

17 files changed

+50
-2
lines changed

17 files changed

+50
-2
lines changed

locales/en-US.yml

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ name: "Name"
400400
antennaSource: "Antenna source"
401401
antennaKeywords: "Keywords to listen to"
402402
antennaExcludeKeywords: "Keywords to exclude"
403+
antennaExcludeBots: "Exclude bots"
403404
antennaKeywordsDescription: "Separate with spaces for an AND condition or with line breaks for an OR condition."
404405
notifyAntenna: "Notify about new notes"
405406
withFileAntenna: "Only notes with files"

locales/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,10 @@ export interface Locale extends ILocale {
16161616
* 除外キーワード
16171617
*/
16181618
"antennaExcludeKeywords": string;
1619+
/**
1620+
* Botアカウントを除外
1621+
*/
1622+
"antennaExcludeBots": string;
16191623
/**
16201624
* スペースで区切るとAND指定になり、改行で区切るとOR指定になります
16211625
*/

locales/ja-JP.yml

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ name: "名前"
400400
antennaSource: "受信ソース"
401401
antennaKeywords: "受信キーワード"
402402
antennaExcludeKeywords: "除外キーワード"
403+
antennaExcludeBots: "Botアカウントを除外"
403404
antennaKeywordsDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります"
404405
notifyAntenna: "新しいノートを通知する"
405406
withFileAntenna: "ファイルが添付されたノートのみ"

locales/ko-KR.yml

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ name: "이름"
400400
antennaSource: "받을 소스"
401401
antennaKeywords: "받을 검색어"
402402
antennaExcludeKeywords: "제외할 검색어"
403+
antennaExcludeBots: "봇 제외"
403404
antennaKeywordsDescription: "공백으로 구분하는 경우 AND, 줄바꿈으로 구분하는 경우 OR로 지정됩니다"
404405
notifyAntenna: "새로운 노트를 알림"
405406
withFileAntenna: "파일이 첨부된 노트만"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class AntennaExcludeBots1710919614510 {
2+
name = 'AntennaExcludeBots1710919614510'
3+
4+
async up(queryRunner) {
5+
await queryRunner.query(`ALTER TABLE "antenna" ADD "excludeBots" boolean NOT NULL DEFAULT false`);
6+
}
7+
8+
async down(queryRunner) {
9+
await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "excludeBots"`);
10+
}
11+
}

packages/backend/src/core/AntennaService.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class AntennaService implements OnApplicationShutdown {
9292
}
9393

9494
@bindThis
95-
public async addNoteToAntennas(note: MiNote, noteUser: { id: MiUser['id']; username: string; host: string | null; }): Promise<void> {
95+
public async addNoteToAntennas(note: MiNote, noteUser: { id: MiUser['id']; username: string; host: string | null; isBot: boolean; }): Promise<void> {
9696
const antennas = await this.getAntennas();
9797
const antennasWithMatchResult = await Promise.all(antennas.map(antenna => this.checkHitAntenna(antenna, note, noteUser).then(hit => [antenna, hit] as const)));
9898
const matchedAntennas = antennasWithMatchResult.filter(([, hit]) => hit).map(([antenna]) => antenna);
@@ -110,10 +110,12 @@ export class AntennaService implements OnApplicationShutdown {
110110
// NOTE: フォローしているユーザーのノート、リストのユーザーのノート、グループのユーザーのノート指定はパフォーマンス上の理由で無効になっている
111111

112112
@bindThis
113-
public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; }): Promise<boolean> {
113+
public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; isBot: boolean; }): Promise<boolean> {
114114
if (note.visibility === 'specified') return false;
115115
if (note.visibility === 'followers') return false;
116116

117+
if (antenna.excludeBots && noteUser.isBot) return false;
118+
117119
if (antenna.localOnly && noteUser.host != null) return false;
118120

119121
if (!antenna.withReplies && note.replyId != null) return false;

packages/backend/src/core/entities/AntennaEntityService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class AntennaEntityService {
3939
caseSensitive: antenna.caseSensitive,
4040
localOnly: antenna.localOnly,
4141
notify: antenna.notify,
42+
excludeBots: antenna.excludeBots,
4243
withReplies: antenna.withReplies,
4344
withFile: antenna.withFile,
4445
isActive: antenna.isActive,

packages/backend/src/models/Antenna.ts

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class MiAntenna {
7272
})
7373
public caseSensitive: boolean;
7474

75+
@Column('boolean', {
76+
default: false,
77+
})
78+
public excludeBots: boolean;
79+
7580
@Column('boolean', {
7681
default: false,
7782
})

packages/backend/src/models/json-schema/antenna.ts

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export const packedAntennaSchema = {
7676
type: 'boolean',
7777
optional: false, nullable: false,
7878
},
79+
excludeBots: {
80+
type: 'boolean',
81+
optional: false, nullable: false,
82+
default: false,
83+
},
7984
withReplies: {
8085
type: 'boolean',
8186
optional: false, nullable: false,

packages/backend/src/queue/processors/ExportAntennasProcessorService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class ExportAntennasProcessorService {
8181
}) : null,
8282
caseSensitive: antenna.caseSensitive,
8383
localOnly: antenna.localOnly,
84+
excludeBots: antenna.excludeBots,
8485
withReplies: antenna.withReplies,
8586
withFile: antenna.withFile,
8687
notify: antenna.notify,

packages/backend/src/queue/processors/ImportAntennasProcessorService.ts

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const validate = new Ajv().compile({
4444
} },
4545
caseSensitive: { type: 'boolean' },
4646
localOnly: { type: 'boolean' },
47+
excludeBots: { type: 'boolean' },
4748
withReplies: { type: 'boolean' },
4849
withFile: { type: 'boolean' },
4950
notify: { type: 'boolean' },
@@ -88,6 +89,7 @@ export class ImportAntennasProcessorService {
8889
users: (antenna.src === 'list' && antenna.userListAccts !== null ? antenna.userListAccts : antenna.users).filter(Boolean),
8990
caseSensitive: antenna.caseSensitive,
9091
localOnly: antenna.localOnly,
92+
excludeBots: antenna.excludeBots,
9193
withReplies: antenna.withReplies,
9294
withFile: antenna.withFile,
9395
notify: antenna.notify,

packages/backend/src/server/api/endpoints/antennas/create.ts

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const paramDef = {
6464
} },
6565
caseSensitive: { type: 'boolean' },
6666
localOnly: { type: 'boolean' },
67+
excludeBots: { type: 'boolean' },
6768
withReplies: { type: 'boolean' },
6869
withFile: { type: 'boolean' },
6970
notify: { type: 'boolean' },
@@ -124,6 +125,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
124125
users: ps.users,
125126
caseSensitive: ps.caseSensitive,
126127
localOnly: ps.localOnly,
128+
excludeBots: ps.excludeBots,
127129
withReplies: ps.withReplies,
128130
withFile: ps.withFile,
129131
notify: ps.notify,

packages/backend/src/server/api/endpoints/antennas/update.ts

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const paramDef = {
6363
} },
6464
caseSensitive: { type: 'boolean' },
6565
localOnly: { type: 'boolean' },
66+
excludeBots: { type: 'boolean' },
6667
withReplies: { type: 'boolean' },
6768
withFile: { type: 'boolean' },
6869
notify: { type: 'boolean' },
@@ -120,6 +121,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
120121
users: ps.users,
121122
caseSensitive: ps.caseSensitive,
122123
localOnly: ps.localOnly,
124+
excludeBots: ps.excludeBots,
123125
withReplies: ps.withReplies,
124126
withFile: ps.withFile,
125127
notify: ps.notify,

packages/backend/test/e2e/antennas.ts

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('アンテナ', () => {
4444
users: [''],
4545
withFile: false,
4646
withReplies: false,
47+
excludeBots: false,
4748
};
4849

4950
let root: User;
@@ -156,6 +157,7 @@ describe('アンテナ', () => {
156157
users: [''],
157158
withFile: false,
158159
withReplies: false,
160+
excludeBots: false,
159161
localOnly: false,
160162
};
161163
assert.deepStrictEqual(response, expected);

packages/frontend/src/pages/my-antennas/create.vue

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const draft = ref({
2626
users: [],
2727
keywords: [],
2828
excludeKeywords: [],
29+
excludeBots: false,
2930
withReplies: false,
3031
caseSensitive: false,
3132
localOnly: false,

packages/frontend/src/pages/my-antennas/editor.vue

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SPDX-License-Identifier: AGPL-3.0-only
2626
<template #label>{{ i18n.ts.users }}</template>
2727
<template #caption>{{ i18n.ts.antennaUsersDescription }} <button class="_textButton" @click="addUser">{{ i18n.ts.addUser }}</button></template>
2828
</MkTextarea>
29+
<MkSwitch v-model="excludeBots">{{ i18n.ts.antennaExcludeBots }}</MkSwitch>
2930
<MkSwitch v-model="withReplies">{{ i18n.ts.withReplies }}</MkSwitch>
3031
<MkTextarea v-model="keywords">
3132
<template #label>{{ i18n.ts.antennaKeywords }}</template>
@@ -78,6 +79,7 @@ const keywords = ref<string>(props.antenna.keywords.map(x => x.join(' ')).join('
7879
const excludeKeywords = ref<string>(props.antenna.excludeKeywords.map(x => x.join(' ')).join('\n'));
7980
const caseSensitive = ref<boolean>(props.antenna.caseSensitive);
8081
const localOnly = ref<boolean>(props.antenna.localOnly);
82+
const excludeBots = ref<boolean>(props.antenna.excludeBots);
8183
const withReplies = ref<boolean>(props.antenna.withReplies);
8284
const withFile = ref<boolean>(props.antenna.withFile);
8385
const notify = ref<boolean>(props.antenna.notify);
@@ -94,6 +96,7 @@ async function saveAntenna() {
9496
name: name.value,
9597
src: src.value,
9698
userListId: userListId.value,
99+
excludeBots: excludeBots.value,
97100
withReplies: withReplies.value,
98101
withFile: withFile.value,
99102
notify: notify.value,

packages/misskey-js/src/autogen/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4434,6 +4434,8 @@ export type components = {
44344434
localOnly: boolean;
44354435
notify: boolean;
44364436
/** @default false */
4437+
excludeBots: boolean;
4438+
/** @default false */
44374439
withReplies: boolean;
44384440
withFile: boolean;
44394441
isActive: boolean;
@@ -9654,6 +9656,7 @@ export type operations = {
96549656
users: string[];
96559657
caseSensitive: boolean;
96569658
localOnly?: boolean;
9659+
excludeBots?: boolean;
96579660
withReplies: boolean;
96589661
withFile: boolean;
96599662
notify: boolean;
@@ -9935,6 +9938,7 @@ export type operations = {
99359938
users?: string[];
99369939
caseSensitive?: boolean;
99379940
localOnly?: boolean;
9941+
excludeBots?: boolean;
99389942
withReplies?: boolean;
99399943
withFile?: boolean;
99409944
notify?: boolean;

0 commit comments

Comments
 (0)