Skip to content

Commit a95ce06

Browse files
authored
enhance(antenna): Botの投稿を除外できるように (MisskeyIO#545)
1 parent c45edf2 commit a95ce06

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
@@ -406,6 +406,7 @@ name: "Name"
406406
antennaSource: "Antenna source"
407407
antennaKeywords: "Keywords to listen to"
408408
antennaExcludeKeywords: "Keywords to exclude"
409+
antennaExcludeBots: "Exclude bots"
409410
antennaKeywordsDescription: "Separate with spaces for an AND condition or with line breaks for an OR condition."
410411
notifyAntenna: "Notify about new notes"
411412
withFileAntenna: "Only notes with files"

locales/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ export interface Locale extends ILocale {
16401640
* 除外キーワード
16411641
*/
16421642
"antennaExcludeKeywords": string;
1643+
/**
1644+
* Botアカウントを除外
1645+
*/
1646+
"antennaExcludeBots": string;
16431647
/**
16441648
* スペースで区切るとAND指定になり、改行で区切るとOR指定になります
16451649
*/

locales/ja-JP.yml

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

locales/ko-KR.yml

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ name: "이름"
405405
antennaSource: "받을 소스"
406406
antennaKeywords: "받을 검색어"
407407
antennaExcludeKeywords: "제외할 검색어"
408+
antennaExcludeBots: "봇 제외"
408409
antennaKeywordsDescription: "공백으로 구분하는 경우 AND, 줄바꿈으로 구분하는 경우 OR로 지정됩니다"
409410
notifyAntenna: "새로운 노트를 알림"
410411
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
@@ -97,7 +97,7 @@ export class AntennaService implements OnApplicationShutdown {
9797
}
9898

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

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

128+
if (antenna.excludeBots && noteUser.isBot) return false;
129+
128130
if (antenna.localOnly && noteUser.host != null) return false;
129131

130132
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
@@ -79,6 +79,11 @@ export class MiAntenna {
7979
})
8080
public caseSensitive: boolean;
8181

82+
@Column('boolean', {
83+
default: false,
84+
})
85+
public excludeBots: boolean;
86+
8287
@Column('boolean', {
8388
default: false,
8489
})

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
@@ -65,6 +65,7 @@ export const paramDef = {
6565
} },
6666
caseSensitive: { type: 'boolean' },
6767
localOnly: { type: 'boolean' },
68+
excludeBots: { type: 'boolean' },
6869
withReplies: { type: 'boolean' },
6970
withFile: { type: 'boolean' },
7071
notify: { type: 'boolean' },
@@ -125,6 +126,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
125126
users: ps.users,
126127
caseSensitive: ps.caseSensitive,
127128
localOnly: ps.localOnly,
129+
excludeBots: ps.excludeBots,
128130
withReplies: ps.withReplies,
129131
withFile: ps.withFile,
130132
notify: ps.notify,

packages/backend/src/server/api/endpoints/antennas/update.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' },
@@ -121,6 +122,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
121122
users: ps.users,
122123
caseSensitive: ps.caseSensitive,
123124
localOnly: ps.localOnly,
125+
excludeBots: ps.excludeBots,
124126
withReplies: ps.withReplies,
125127
withFile: ps.withFile,
126128
notify: ps.notify,

packages/backend/test/e2e/antennas.ts

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

5051
let root: User;
@@ -159,6 +160,7 @@ describe('アンテナ', () => {
159160
users: [''],
160161
withFile: false,
161162
withReplies: false,
163+
excludeBots: false,
162164
localOnly: false,
163165
};
164166
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
@@ -4586,6 +4586,8 @@ export type components = {
45864586
localOnly: boolean;
45874587
notify: boolean;
45884588
/** @default false */
4589+
excludeBots: boolean;
4590+
/** @default false */
45894591
withReplies: boolean;
45904592
withFile: boolean;
45914593
isActive: boolean;
@@ -10618,6 +10620,7 @@ export type operations = {
1061810620
users: string[];
1061910621
caseSensitive: boolean;
1062010622
localOnly?: boolean;
10623+
excludeBots?: boolean;
1062110624
withReplies: boolean;
1062210625
withFile: boolean;
1062310626
notify: boolean;
@@ -10899,6 +10902,7 @@ export type operations = {
1089910902
users?: string[];
1090010903
caseSensitive?: boolean;
1090110904
localOnly?: boolean;
10905+
excludeBots?: boolean;
1090210906
withReplies?: boolean;
1090310907
withFile?: boolean;
1090410908
notify?: boolean;

0 commit comments

Comments
 (0)