Compare commits

..

2 commits

Author SHA1 Message Date
かなた 31abe7146e
#102の変更で不要になった引数を削除 (#103) 2023-02-25 19:36:00 +09:00
syuilo fb271619cc
チャット機能削除に対応 (#102) 2023-02-25 13:42:56 +09:00
9 changed files with 54 additions and 143 deletions

View file

@ -53,7 +53,6 @@ export default class 藍 {
private meta: loki.Collection<Meta>; private meta: loki.Collection<Meta>;
private contexts: loki.Collection<{ private contexts: loki.Collection<{
isDm: boolean;
noteId?: string; noteId?: string;
userId?: string; userId?: string;
module: string; module: string;
@ -146,7 +145,7 @@ export default class 藍 {
if (data.text && data.text.startsWith('@' + this.account.username)) { if (data.text && data.text.startsWith('@' + this.account.username)) {
// Misskeyのバグで投稿が非公開扱いになる // Misskeyのバグで投稿が非公開扱いになる
if (data.text == null) data = await this.api('notes/show', { noteId: data.id }); if (data.text == null) data = await this.api('notes/show', { noteId: data.id });
this.onReceiveMessage(new Message(this, data, false)); this.onReceiveMessage(new Message(this, data));
} }
}); });
@ -156,7 +155,7 @@ export default class 藍 {
if (data.text && data.text.startsWith('@' + this.account.username)) return; if (data.text && data.text.startsWith('@' + this.account.username)) return;
// Misskeyのバグで投稿が非公開扱いになる // Misskeyのバグで投稿が非公開扱いになる
if (data.text == null) data = await this.api('notes/show', { noteId: data.id }); if (data.text == null) data = await this.api('notes/show', { noteId: data.id });
this.onReceiveMessage(new Message(this, data, false)); this.onReceiveMessage(new Message(this, data));
}); });
// Renoteされたとき // Renoteされたとき
@ -174,7 +173,7 @@ export default class 藍 {
// メッセージ // メッセージ
mainStream.on('messagingMessage', data => { mainStream.on('messagingMessage', data => {
if (data.userId == this.account.id) return; // 自分は弾く if (data.userId == this.account.id) return; // 自分は弾く
this.onReceiveMessage(new Message(this, data, true)); this.onReceiveMessage(new Message(this, data));
}); });
// 通知 // 通知
@ -218,14 +217,10 @@ export default class 藍 {
return; return;
} }
const isNoContext = !msg.isDm && msg.replyId == null; const isNoContext = msg.replyId == null;
// Look up the context // Look up the context
const context = isNoContext ? null : this.contexts.findOne(msg.isDm ? { const context = isNoContext ? null : this.contexts.findOne({
isDm: true,
userId: msg.userId
} : {
isDm: false,
noteId: msg.replyId noteId: msg.replyId
}); });
@ -270,12 +265,6 @@ export default class 藍 {
await delay(1000); await delay(1000);
} }
if (msg.isDm) {
// 既読にする
this.api('messaging/messages/read', {
messageId: msg.id,
});
} else {
// リアクションする // リアクションする
if (reaction) { if (reaction) {
this.api('notes/reactions/create', { this.api('notes/reactions/create', {
@ -284,7 +273,6 @@ export default class 藍 {
}); });
} }
} }
}
@autobind @autobind
private onNotification(notification: any) { private onNotification(notification: any) {
@ -405,20 +393,12 @@ export default class 藍 {
* *
* @param module 待ち受けるモジュール名 * @param module 待ち受けるモジュール名
* @param key * @param key
* @param isDm
* @param id ID稿ID * @param id ID稿ID
* @param data * @param data
*/ */
@autobind @autobind
public subscribeReply(module: Module, key: string | null, isDm: boolean, id: string, data?: any) { public subscribeReply(module: Module, key: string | null, id: string, data?: any) {
this.contexts.insertOne(isDm ? { this.contexts.insertOne({
isDm: true,
userId: id,
module: module.name,
key: key,
data: data
} : {
isDm: false,
noteId: id, noteId: id,
module: module.name, module: module.name,
key: key, key: key,

View file

@ -11,31 +11,30 @@ import config from '@/config';
export default class Message { export default class Message {
private ai: ; private ai: ;
private messageOrNote: any; private note: any;
public isDm: boolean;
public get id(): string { public get id(): string {
return this.messageOrNote.id; return this.note.id;
} }
public get user(): User { public get user(): User {
return this.messageOrNote.user; return this.note.user;
} }
public get userId(): string { public get userId(): string {
return this.messageOrNote.userId; return this.note.userId;
} }
public get text(): string { public get text(): string {
return this.messageOrNote.text; return this.note.text;
} }
public get quoteId(): string | null { public get quoteId(): string | null {
return this.messageOrNote.renoteId; return this.note.renoteId;
} }
public get visibility(): string { public get visibility(): string {
return this.messageOrNote.visibility; return this.note.visibility;
} }
/** /**
@ -50,15 +49,14 @@ export default class Message {
} }
public get replyId(): string { public get replyId(): string {
return this.messageOrNote.replyId; return this.note.replyId;
} }
public friend: Friend; public friend: Friend;
constructor(ai: , messageOrNote: any, isDm: boolean) { constructor(ai: , note: any) {
this.ai = ai; this.ai = ai;
this.messageOrNote = messageOrNote; this.note = note;
this.isDm = isDm;
this.friend = new Friend(ai, { user: this.user }); this.friend = new Friend(ai, { user: this.user });
@ -85,21 +83,14 @@ export default class Message {
await delay(2000); await delay(2000);
} }
if (this.isDm) {
return await this.ai.sendMessage(this.messageOrNote.userId, {
text: text,
fileId: opts?.file?.id
});
} else {
return await this.ai.post({ return await this.ai.post({
replyId: this.messageOrNote.id, replyId: this.note.id,
text: text, text: text,
fileIds: opts?.file ? [opts?.file.id] : undefined, fileIds: opts?.file ? [opts?.file.id] : undefined,
cw: opts?.cw, cw: opts?.cw,
renoteId: opts?.renote renoteId: opts?.renote
}); });
} }
}
@autobind @autobind
public includes(words: string[]): boolean { public includes(words: string[]): boolean {

View file

@ -32,13 +32,12 @@ export default abstract class Module {
/** /**
* *
* @param key * @param key
* @param isDm
* @param id ID稿ID * @param id ID稿ID
* @param data * @param data
*/ */
@autobind @autobind
protected subscribeReply(key: string | null, isDm: boolean, id: string, data?: any) { protected subscribeReply(key: string | null, id: string, data?: any) {
this.ai.subscribeReply(this, key, isDm, id, data); this.ai.subscribeReply(this, key, id, data);
} }
/** /**

View file

@ -35,12 +35,6 @@ export default class extends Module {
if (!msg.text) return false; if (!msg.text) return false;
if (!msg.includes(['引継', '引き継ぎ', '引越', '引っ越し'])) return false; if (!msg.includes(['引継', '引き継ぎ', '引越', '引っ越し'])) return false;
// メッセージのみ
if (!msg.isDm) {
msg.reply(serifs.core.transferNeedDm);
return true;
}
const code = msg.friend.generateTransferCode(); const code = msg.friend.generateTransferCode();
msg.reply(serifs.core.transferCode(code)); msg.reply(serifs.core.transferCode(code));
@ -72,9 +66,6 @@ export default class extends Module {
if (!msg.text.includes('って呼んで')) return false; if (!msg.text.includes('って呼んで')) return false;
if (msg.text.startsWith('って呼んで')) return false; if (msg.text.startsWith('って呼んで')) return false;
// メッセージのみ
if (!msg.isDm) return true;
const name = msg.text.match(/^(.+?)って呼んで/)![1]; const name = msg.text.match(/^(.+?)って呼んで/)![1];
if (name.length > 10) { if (name.length > 10) {
@ -94,7 +85,7 @@ export default class extends Module {
msg.reply(serifs.core.setNameOk(name)); msg.reply(serifs.core.setNameOk(name));
} else { } else {
msg.reply(serifs.core.san).then(reply => { msg.reply(serifs.core.san).then(reply => {
this.subscribeReply(msg.userId, msg.isDm, msg.isDm ? msg.userId : reply.id, { this.subscribeReply(msg.userId, reply.id, {
name: name name: name
}); });
}); });
@ -152,7 +143,7 @@ export default class extends Module {
done(); done();
} else { } else {
msg.reply(serifs.core.yesOrNo).then(reply => { msg.reply(serifs.core.yesOrNo).then(reply => {
this.subscribeReply(msg.userId, msg.isDm, reply.id, data); this.subscribeReply(msg.userId, reply.id, data);
}); });
} }
} }

View file

@ -37,16 +37,6 @@ export default class extends Module {
isEnded: false isEnded: false
}); });
if (!msg.isDm) {
if (exist != null) {
msg.reply(serifs.guessingGame.alreadyStarted);
} else {
msg.reply(serifs.guessingGame.plzDm);
}
return true;
}
const secret = Math.floor(Math.random() * 100); const secret = Math.floor(Math.random() * 100);
this.guesses.insertOne({ this.guesses.insertOne({
@ -59,7 +49,7 @@ export default class extends Module {
}); });
msg.reply(serifs.guessingGame.started).then(reply => { msg.reply(serifs.guessingGame.started).then(reply => {
this.subscribeReply(msg.userId, msg.isDm, msg.isDm ? msg.userId : reply.id); this.subscribeReply(msg.userId, reply.id);
}); });
return true; return true;
@ -93,7 +83,7 @@ export default class extends Module {
if (guess == null) { if (guess == null) {
msg.reply(serifs.guessingGame.nan).then(reply => { msg.reply(serifs.guessingGame.nan).then(reply => {
this.subscribeReply(msg.userId, msg.isDm, reply.id); this.subscribeReply(msg.userId, reply.id);
}); });
return; return;
} }
@ -131,7 +121,7 @@ export default class extends Module {
msg.reply(text).then(reply => { msg.reply(text).then(reply => {
if (!end) { if (!end) {
this.subscribeReply(msg.userId, msg.isDm, reply.id); this.subscribeReply(msg.userId, reply.id);
} }
}); });
} }

View file

@ -75,7 +75,7 @@ export default class extends Module {
postId: post.id postId: post.id
}); });
this.subscribeReply(null, false, post.id); this.subscribeReply(null, post.id);
this.log('New kazutori game started'); this.log('New kazutori game started');

View file

@ -14,7 +14,6 @@ export default class extends Module {
private reminds: loki.Collection<{ private reminds: loki.Collection<{
userId: string; userId: string;
id: string; id: string;
isDm: boolean;
thing: string | null; thing: string | null;
quoteId: string | null; quoteId: string | null;
times: number; // 催促した回数(使うのか?) times: number; // 催促した回数(使うのか?)
@ -70,7 +69,6 @@ export default class extends Module {
const remind = this.reminds.insertOne({ const remind = this.reminds.insertOne({
id: msg.id, id: msg.id,
userId: msg.userId, userId: msg.userId,
isDm: msg.isDm,
thing: thing === '' ? null : thing, thing: thing === '' ? null : thing,
quoteId: msg.quoteId, quoteId: msg.quoteId,
times: 0, times: 0,
@ -78,13 +76,13 @@ export default class extends Module {
}); });
// メンションをsubscribe // メンションをsubscribe
this.subscribeReply(remind!.id, msg.isDm, msg.isDm ? msg.userId : msg.id, { this.subscribeReply(remind!.id, msg.id, {
id: remind!.id id: remind!.id
}); });
if (msg.quoteId) { if (msg.quoteId) {
// 引用元をsubscribe // 引用元をsubscribe
this.subscribeReply(remind!.id, false, msg.quoteId, { this.subscribeReply(remind!.id, msg.quoteId, {
id: remind!.id id: remind!.id
}); });
} }
@ -126,7 +124,6 @@ export default class extends Module {
msg.reply(serifs.reminder.doneFromInvalidUser); msg.reply(serifs.reminder.doneFromInvalidUser);
return; return;
} else { } else {
if (msg.isDm) this.unsubscribeReply(key);
return false; return false;
} }
} }
@ -145,11 +142,6 @@ export default class extends Module {
if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応 if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応
let reply; let reply;
if (remind.isDm) {
this.ai.sendMessage(friend.userId, {
text: serifs.reminder.notifyWithThing(remind.thing, friend.name)
});
} else {
try { try {
reply = await this.ai.post({ reply = await this.ai.post({
renoteId: remind.thing == null && remind.quoteId ? remind.quoteId : remind.id, renoteId: remind.thing == null && remind.quoteId ? remind.quoteId : remind.id,
@ -164,9 +156,8 @@ export default class extends Module {
} }
return; return;
} }
}
this.subscribeReply(remind.id, remind.isDm, remind.isDm ? remind.userId : reply.id, { this.subscribeReply(remind.id, reply.id, {
id: remind.id id: remind.id
}); });

View file

@ -146,9 +146,6 @@ export default class extends Module {
private nadenade(msg: Message): boolean { private nadenade(msg: Message): boolean {
if (!msg.includes(['なでなで'])) return false; if (!msg.includes(['なでなで'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
//#region 1日に1回だけ親愛度を上げる(嫌われてない場合のみ) //#region 1日に1回だけ親愛度を上げる(嫌われてない場合のみ)
if (msg.friend.love >= 0) { if (msg.friend.love >= 0) {
const today = getDate(); const today = getDate();
@ -181,9 +178,6 @@ export default class extends Module {
private kawaii(msg: Message): boolean { private kawaii(msg: Message): boolean {
if (!msg.includes(['かわいい', '可愛い'])) return false; if (!msg.includes(['かわいい', '可愛い'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply(getSerif( msg.reply(getSerif(
msg.friend.love >= 5 ? serifs.core.kawaii.love : msg.friend.love >= 5 ? serifs.core.kawaii.love :
msg.friend.love <= -3 ? serifs.core.kawaii.hate : msg.friend.love <= -3 ? serifs.core.kawaii.hate :
@ -196,9 +190,6 @@ export default class extends Module {
private suki(msg: Message): boolean { private suki(msg: Message): boolean {
if (!msg.or(['好き', 'すき'])) return false; if (!msg.or(['好き', 'すき'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply( msg.reply(
msg.friend.love >= 5 ? (msg.friend.name ? serifs.core.suki.love(msg.friend.name) : serifs.core.suki.normal) : msg.friend.love >= 5 ? (msg.friend.name ? serifs.core.suki.love(msg.friend.name) : serifs.core.suki.normal) :
msg.friend.love <= -3 ? serifs.core.suki.hate : msg.friend.love <= -3 ? serifs.core.suki.hate :
@ -211,9 +202,6 @@ export default class extends Module {
private hug(msg: Message): boolean { private hug(msg: Message): boolean {
if (!msg.or(['ぎゅ', 'むぎゅ', /^はぐ(し(て|よ|よう)?)?$/])) return false; if (!msg.or(['ぎゅ', 'むぎゅ', /^はぐ(し(て|よ|よう)?)?$/])) return false;
// メッセージのみ
if (!msg.isDm) return true;
//#region 前のハグから1分経ってない場合は返信しない //#region 前のハグから1分経ってない場合は返信しない
// これは、「ハグ」と言って「ぎゅー」と返信したとき、相手が // これは、「ハグ」と言って「ぎゅー」と返信したとき、相手が
// それに対してさらに「ぎゅー」と返信するケースがあったため。 // それに対してさらに「ぎゅー」と返信するケースがあったため。
@ -245,9 +233,6 @@ export default class extends Module {
private humu(msg: Message): boolean { private humu(msg: Message): boolean {
if (!msg.includes(['踏んで'])) return false; if (!msg.includes(['踏んで'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply( msg.reply(
msg.friend.love >= 5 ? serifs.core.humu.love : msg.friend.love >= 5 ? serifs.core.humu.love :
msg.friend.love <= -3 ? serifs.core.humu.hate : msg.friend.love <= -3 ? serifs.core.humu.hate :
@ -260,9 +245,6 @@ export default class extends Module {
private batou(msg: Message): boolean { private batou(msg: Message): boolean {
if (!msg.includes(['罵倒して', '罵って'])) return false; if (!msg.includes(['罵倒して', '罵って'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply( msg.reply(
msg.friend.love >= 5 ? serifs.core.batou.love : msg.friend.love >= 5 ? serifs.core.batou.love :
msg.friend.love <= -5 ? serifs.core.batou.hate : msg.friend.love <= -5 ? serifs.core.batou.hate :
@ -275,9 +257,6 @@ export default class extends Module {
private itai(msg: Message): boolean { private itai(msg: Message): boolean {
if (!msg.or(['痛い', 'いたい']) && !msg.extractedText.endsWith('痛い')) return false; if (!msg.or(['痛い', 'いたい']) && !msg.extractedText.endsWith('痛い')) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply(serifs.core.itai(msg.friend.name)); msg.reply(serifs.core.itai(msg.friend.name));
return true; return true;
@ -287,9 +266,6 @@ export default class extends Module {
private ote(msg: Message): boolean { private ote(msg: Message): boolean {
if (!msg.or(['お手'])) return false; if (!msg.or(['お手'])) return false;
// メッセージのみ
if (!msg.isDm) return true;
msg.reply( msg.reply(
msg.friend.love >= 10 ? serifs.core.ote.love2 : msg.friend.love >= 10 ? serifs.core.ote.love2 :
msg.friend.love >= 5 ? serifs.core.ote.love1 : msg.friend.love >= 5 ? serifs.core.ote.love1 :

View file

@ -47,7 +47,6 @@ export default class extends Module {
// タイマーセット // タイマーセット
this.setTimeoutWithPersistence(time, { this.setTimeoutWithPersistence(time, {
isDm: msg.isDm,
msgId: msg.id, msgId: msg.id,
userId: msg.friend.userId, userId: msg.friend.userId,
time: str time: str
@ -61,15 +60,9 @@ export default class extends Module {
const friend = this.ai.lookupFriend(data.userId); const friend = this.ai.lookupFriend(data.userId);
if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応 if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応
const text = serifs.timer.notify(data.time, friend.name); const text = serifs.timer.notify(data.time, friend.name);
if (data.isDm) {
this.ai.sendMessage(friend.userId, {
text: text
});
} else {
this.ai.post({ this.ai.post({
replyId: data.msgId, replyId: data.msgId,
text: text text: text
}); });
} }
}
} }