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

View file

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

View file

@ -32,12 +32,13 @@ export default abstract class Module {
/**
*
* @param key
* @param isDm
* @param id ID稿ID
* @param data
*/
@autobind
protected subscribeReply(key: string | null, id: string, data?: any) {
this.ai.subscribeReply(this, key, id, data);
protected subscribeReply(key: string | null, isDm: boolean, id: string, data?: any) {
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.includes(['引継', '引き継ぎ', '引越', '引っ越し'])) return false;
// メッセージのみ
if (!msg.isDm) {
msg.reply(serifs.core.transferNeedDm);
return true;
}
const code = msg.friend.generateTransferCode();
msg.reply(serifs.core.transferCode(code));
@ -66,6 +72,9 @@ export default class extends Module {
if (!msg.text.includes('って呼んで')) return false;
if (msg.text.startsWith('って呼んで')) return false;
// メッセージのみ
if (!msg.isDm) return true;
const name = msg.text.match(/^(.+?)って呼んで/)![1];
if (name.length > 10) {
@ -85,7 +94,7 @@ export default class extends Module {
msg.reply(serifs.core.setNameOk(name));
} else {
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
});
});
@ -143,7 +152,7 @@ export default class extends Module {
done();
} else {
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
});
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);
this.guesses.insertOne({
@ -49,7 +59,7 @@ export default class extends Module {
});
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;
@ -83,7 +93,7 @@ export default class extends Module {
if (guess == null) {
msg.reply(serifs.guessingGame.nan).then(reply => {
this.subscribeReply(msg.userId, reply.id);
this.subscribeReply(msg.userId, msg.isDm, reply.id);
});
return;
}
@ -121,7 +131,7 @@ export default class extends Module {
msg.reply(text).then(reply => {
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
});
this.subscribeReply(null, post.id);
this.subscribeReply(null, false, post.id);
this.log('New kazutori game started');

View file

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

View file

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

View file

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