Compare commits

..

No commits in common. "31abe7146ed7fa8996568aa20b03c1ce06eae163" and "ecb983089cb1366cffe62afa633d0d2273ac6671" have entirely different histories.

9 changed files with 143 additions and 54 deletions

View file

@ -53,6 +53,7 @@ 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;
@ -145,7 +146,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)); this.onReceiveMessage(new Message(this, data, false));
} }
}); });
@ -155,7 +156,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)); this.onReceiveMessage(new Message(this, data, false));
}); });
// Renoteされたとき // Renoteされたとき
@ -173,7 +174,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)); this.onReceiveMessage(new Message(this, data, true));
}); });
// 通知 // 通知
@ -217,10 +218,14 @@ export default class 藍 {
return; return;
} }
const isNoContext = msg.replyId == null; const isNoContext = !msg.isDm && msg.replyId == null;
// Look up the context // Look up the context
const context = isNoContext ? null : this.contexts.findOne({ const context = isNoContext ? null : this.contexts.findOne(msg.isDm ? {
isDm: true,
userId: msg.userId
} : {
isDm: false,
noteId: msg.replyId noteId: msg.replyId
}); });
@ -265,12 +270,19 @@ export default class 藍 {
await delay(1000); await delay(1000);
} }
// リアクションする if (msg.isDm) {
if (reaction) { // 既読にする
this.api('notes/reactions/create', { this.api('messaging/messages/read', {
noteId: msg.id, messageId: msg.id,
reaction: reaction
}); });
} else {
// リアクションする
if (reaction) {
this.api('notes/reactions/create', {
noteId: msg.id,
reaction: reaction
});
}
} }
} }
@ -393,12 +405,20 @@ 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, id: string, data?: any) { public subscribeReply(module: Module, key: string | null, isDm: boolean, id: string, data?: any) {
this.contexts.insertOne({ this.contexts.insertOne(isDm ? {
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,30 +11,31 @@ import config from '@/config';
export default class Message { export default class Message {
private ai: ; private ai: ;
private note: any; private messageOrNote: any;
public isDm: boolean;
public get id(): string { public get id(): string {
return this.note.id; return this.messageOrNote.id;
} }
public get user(): User { public get user(): User {
return this.note.user; return this.messageOrNote.user;
} }
public get userId(): string { public get userId(): string {
return this.note.userId; return this.messageOrNote.userId;
} }
public get text(): string { public get text(): string {
return this.note.text; return this.messageOrNote.text;
} }
public get quoteId(): string | null { public get quoteId(): string | null {
return this.note.renoteId; return this.messageOrNote.renoteId;
} }
public get visibility(): string { public get visibility(): string {
return this.note.visibility; return this.messageOrNote.visibility;
} }
/** /**
@ -49,14 +50,15 @@ export default class Message {
} }
public get replyId(): string { public get replyId(): string {
return this.note.replyId; return this.messageOrNote.replyId;
} }
public friend: Friend; public friend: Friend;
constructor(ai: , note: any) { constructor(ai: , messageOrNote: any, isDm: boolean) {
this.ai = ai; this.ai = ai;
this.note = note; this.messageOrNote = messageOrNote;
this.isDm = isDm;
this.friend = new Friend(ai, { user: this.user }); this.friend = new Friend(ai, { user: this.user });
@ -83,13 +85,20 @@ export default class Message {
await delay(2000); await delay(2000);
} }
return await this.ai.post({ if (this.isDm) {
replyId: this.note.id, return await this.ai.sendMessage(this.messageOrNote.userId, {
text: text, text: text,
fileIds: opts?.file ? [opts?.file.id] : undefined, fileId: opts?.file?.id
cw: opts?.cw, });
renoteId: opts?.renote } else {
}); return await this.ai.post({
replyId: this.messageOrNote.id,
text: text,
fileIds: opts?.file ? [opts?.file.id] : undefined,
cw: opts?.cw,
renoteId: opts?.renote
});
}
} }
@autobind @autobind

View file

@ -32,12 +32,13 @@ 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, id: string, data?: any) { protected subscribeReply(key: string | null, isDm: boolean, id: string, data?: any) {
this.ai.subscribeReply(this, key, id, data); this.ai.subscribeReply(this, key, isDm, id, data);
} }
/** /**

View file

@ -35,6 +35,12 @@ 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));
@ -66,6 +72,9 @@ 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) {
@ -85,7 +94,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, reply.id, { this.subscribeReply(msg.userId, msg.isDm, msg.isDm ? msg.userId : reply.id, {
name: name name: name
}); });
}); });
@ -143,7 +152,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, reply.id, data); this.subscribeReply(msg.userId, msg.isDm, reply.id, data);
}); });
} }
} }

View file

@ -37,6 +37,16 @@ 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({
@ -49,7 +59,7 @@ export default class extends Module {
}); });
msg.reply(serifs.guessingGame.started).then(reply => { msg.reply(serifs.guessingGame.started).then(reply => {
this.subscribeReply(msg.userId, reply.id); this.subscribeReply(msg.userId, msg.isDm, msg.isDm ? msg.userId : reply.id);
}); });
return true; return true;
@ -83,7 +93,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, reply.id); this.subscribeReply(msg.userId, msg.isDm, reply.id);
}); });
return; return;
} }
@ -121,7 +131,7 @@ export default class extends Module {
msg.reply(text).then(reply => { msg.reply(text).then(reply => {
if (!end) { if (!end) {
this.subscribeReply(msg.userId, reply.id); this.subscribeReply(msg.userId, msg.isDm, reply.id);
} }
}); });
} }

View file

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

View file

@ -14,6 +14,7 @@ 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; // 催促した回数(使うのか?)
@ -69,6 +70,7 @@ 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,
@ -76,13 +78,13 @@ export default class extends Module {
}); });
// メンションをsubscribe // メンションをsubscribe
this.subscribeReply(remind!.id, msg.id, { this.subscribeReply(remind!.id, msg.isDm, msg.isDm ? msg.userId : msg.id, {
id: remind!.id id: remind!.id
}); });
if (msg.quoteId) { if (msg.quoteId) {
// 引用元をsubscribe // 引用元をsubscribe
this.subscribeReply(remind!.id, msg.quoteId, { this.subscribeReply(remind!.id, false, msg.quoteId, {
id: remind!.id id: remind!.id
}); });
} }
@ -124,6 +126,7 @@ 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;
} }
} }
@ -142,22 +145,28 @@ export default class extends Module {
if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応 if (friend == null) return; // 処理の流れ上、実際にnullになることは無さそうだけど一応
let reply; let reply;
try { if (remind.isDm) {
reply = await this.ai.post({ this.ai.sendMessage(friend.userId, {
renoteId: remind.thing == null && remind.quoteId ? remind.quoteId : remind.id, text: serifs.reminder.notifyWithThing(remind.thing, friend.name)
text: acct(friend.doc.user) + ' ' + serifs.reminder.notify(friend.name)
}); });
} catch (err) { } else {
// renote対象が消されていたらリマインダー解除 try {
if (err.statusCode === 400) { reply = await this.ai.post({
this.unsubscribeReply(remind.thing == null && remind.quoteId ? remind.quoteId : remind.id); renoteId: remind.thing == null && remind.quoteId ? remind.quoteId : remind.id,
this.reminds.remove(remind); text: acct(friend.doc.user) + ' ' + serifs.reminder.notify(friend.name)
});
} catch (err) {
// renote対象が消されていたらリマインダー解除
if (err.statusCode === 400) {
this.unsubscribeReply(remind.thing == null && remind.quoteId ? remind.quoteId : remind.id);
this.reminds.remove(remind);
return;
}
return; return;
} }
return;
} }
this.subscribeReply(remind.id, reply.id, { this.subscribeReply(remind.id, remind.isDm, remind.isDm ? remind.userId : reply.id, {
id: remind.id id: remind.id
}); });

View file

@ -146,6 +146,9 @@ 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();
@ -178,6 +181,9 @@ 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 :
@ -190,6 +196,9 @@ 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 :
@ -202,6 +211,9 @@ 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分経ってない場合は返信しない
// これは、「ハグ」と言って「ぎゅー」と返信したとき、相手が // これは、「ハグ」と言って「ぎゅー」と返信したとき、相手が
// それに対してさらに「ぎゅー」と返信するケースがあったため。 // それに対してさらに「ぎゅー」と返信するケースがあったため。
@ -233,6 +245,9 @@ 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 :
@ -245,6 +260,9 @@ 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 :
@ -257,6 +275,9 @@ 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;
@ -266,6 +287,9 @@ 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,6 +47,7 @@ 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
@ -60,9 +61,15 @@ 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);
this.ai.post({ if (data.isDm) {
replyId: data.msgId, this.ai.sendMessage(friend.userId, {
text: text text: text
}); });
} else {
this.ai.post({
replyId: data.msgId,
text: text
});
}
} }
} }