This commit is contained in:
syuilo 2020-08-25 10:08:27 +09:00
parent f7ca0bb726
commit 53c54f6f14
6 changed files with 84 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import 藍 from './ai';
import IModule from './module'; import IModule from './module';
import getDate from './utils/get-date'; import getDate from './utils/get-date';
import { User } from './misskey/user'; import { User } from './misskey/user';
import { itemPrefixes, items, and } from './vocabulary';
export type FriendDoc = { export type FriendDoc = {
userId: string; userId: string;
@ -13,6 +14,7 @@ export type FriendDoc = {
todayLoveIncrements?: number; todayLoveIncrements?: number;
perModulesData?: any; perModulesData?: any;
married?: boolean; married?: boolean;
transferCode?: string;
}; };
export default class Friend { export default class Friend {
@ -137,4 +139,38 @@ export default class Friend {
public save() { public save() {
this.ai.friends.update(this.doc); this.ai.friends.update(this.doc);
} }
@autobind
public generateTransferCode(): string {
let code = '';
code += itemPrefixes[Math.floor(Math.random() * itemPrefixes.length)];
code += items[Math.floor(Math.random() * items.length)];
code += and[Math.floor(Math.random() * and.length)];
code += itemPrefixes[Math.floor(Math.random() * itemPrefixes.length)];
code += items[Math.floor(Math.random() * items.length)];
this.doc.transferCode = code;
this.save();
return code;
}
@autobind
public transferMemory(code: string): boolean {
const src = this.ai.friends.findOne({
transferCode: code
});
if (src == null) return false;
this.doc.name = src.name;
this.doc.love = src.love;
this.doc.married = src.married;
this.doc.perModulesData = src.perModulesData;
this.save();
// TODO: 合言葉を忘れる
return true;
}
} }

View file

@ -3,7 +3,7 @@ import Module from '../../module';
import serifs from '../../serifs'; import serifs from '../../serifs';
import Message from '../../message'; import Message from '../../message';
import { renderChart } from './render-chart'; import { renderChart } from './render-chart';
import { items } from '../fortune/vocabulary'; import { items } from '../../vocabulary';
import config from '../../config'; import config from '../../config';
export default class extends Module { export default class extends Module {

View file

@ -25,6 +25,8 @@ export default class extends Module {
if (!msg.text) return false; if (!msg.text) return false;
return ( return (
this.transferBegin(msg) ||
this.transferEnd(msg) ||
this.setName(msg) || this.setName(msg) ||
this.greet(msg) || this.greet(msg) ||
this.erait(msg) || this.erait(msg) ||
@ -43,6 +45,42 @@ export default class extends Module {
); );
} }
@autobind
private transferBegin(msg: Message): boolean {
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));
return true;
}
@autobind
private transferEnd(msg: Message): boolean {
if (!msg.text) return false;
if (!msg.text.startsWith('「') || !msg.text.endsWith('」')) return false;
const code = msg.text.substring(1, msg.text.length - 1);
const succ = msg.friend.transferMemory(code);
if (succ) {
msg.reply(serifs.core.transferDone(msg.friend.name));
} else {
msg.reply(serifs.core.transferFailed);
}
return true;
}
@autobind @autobind
private setName(msg: Message): boolean { private setName(msg: Message): boolean {
if (!msg.text) return false; if (!msg.text) return false;

View file

@ -3,7 +3,7 @@ import Module from '../../module';
import Message from '../../message'; import Message from '../../message';
import serifs from '../../serifs'; import serifs from '../../serifs';
import * as seedrandom from 'seedrandom'; import * as seedrandom from 'seedrandom';
import { blessing, itemPrefixes, items, and } from './vocabulary'; import { blessing, itemPrefixes, items, and } from '../../vocabulary';
export default class extends Module { export default class extends Module {
public readonly name = 'fortune'; public readonly name = 'fortune';

View file

@ -145,6 +145,14 @@ export default {
}, },
shutdown: '私まだ眠くないですよ...', shutdown: '私まだ眠くないですよ...',
transferNeedDm: 'わかりました、それはチャットで話しませんか?',
transferCode: code => `わかりました。\n合言葉は「${code}」です!`,
transferFailed: 'うーん、合言葉が間違ってませんか...',
transferDone: name => name ? `はっ... おかえりなさい、${name}` : `はっ... おかえりなさい!`,
}, },
keyword: { keyword: {