mirror of
https://github.com/syuilo/ai.git
synced 2024-11-09 15:38:00 +00:00
manual maze request
This commit is contained in:
parent
5ac502d401
commit
ace5bf8f8f
|
@ -80,6 +80,30 @@ export default class Message {
|
|||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async replyWithFile(text: string, file: any, cw?: string, renote?: string) {
|
||||
if (text == null) return;
|
||||
|
||||
this.ai.log(`>>> Sending reply to ${chalk.underline(this.id)}`);
|
||||
|
||||
await delay(2000);
|
||||
|
||||
if (this.isDm) {
|
||||
return await this.ai.sendMessage(this.messageOrNote.userId, {
|
||||
text: text,
|
||||
fileId: file.id
|
||||
});
|
||||
} else {
|
||||
return await this.ai.post({
|
||||
replyId: this.messageOrNote.id,
|
||||
text: text,
|
||||
fileIds: [file.id],
|
||||
cw: cw,
|
||||
renoteId: renote
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
public includes(words: string[]): boolean {
|
||||
return includes(this.text, words);
|
||||
|
|
|
@ -5,6 +5,7 @@ import serifs from '../../serifs';
|
|||
import * as tmp from 'tmp';
|
||||
import { genMaze } from './gen-maze';
|
||||
import { renderMaze } from './render-maze';
|
||||
import Message from '../../message';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'maze';
|
||||
|
@ -14,7 +15,9 @@ export default class extends Module {
|
|||
this.post();
|
||||
setInterval(this.post, 1000 * 60 * 3);
|
||||
|
||||
return {};
|
||||
return {
|
||||
mentionHook: this.mentionHook
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
|
@ -27,17 +30,8 @@ export default class extends Module {
|
|||
data.lastPosted = date;
|
||||
this.setData(data);
|
||||
|
||||
const seed = date;
|
||||
|
||||
this.log('Maze generating...');
|
||||
const maze = genMaze(seed);
|
||||
|
||||
this.log('Maze rendering...');
|
||||
const [temp] = await this.createTemp();
|
||||
await renderMaze(seed, maze, fs.createWriteStream(temp));
|
||||
|
||||
this.log('Image uploading...');
|
||||
const file = await this.ai.upload(fs.createReadStream(temp));
|
||||
this.log('Time to maze');
|
||||
const file = await this.genMazeFile(date);
|
||||
|
||||
this.log('Posting...');
|
||||
this.ai.post({
|
||||
|
@ -55,4 +49,36 @@ export default class extends Module {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
private async genMazeFile(seed): Promise<any> {
|
||||
this.log('Maze generating...');
|
||||
const maze = genMaze(seed);
|
||||
|
||||
this.log('Maze rendering...');
|
||||
const [temp] = await this.createTemp();
|
||||
await renderMaze(seed, maze, fs.createWriteStream(temp));
|
||||
|
||||
this.log('Image uploading...');
|
||||
const file = await this.ai.upload(fs.createReadStream(temp));
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@autobind
|
||||
private async mentionHook(msg: Message) {
|
||||
if (msg.includes(['迷路'])) {
|
||||
this.log('Maze requested');
|
||||
setTimeout(async () => {
|
||||
const file = await this.genMazeFile(Date.now());
|
||||
this.log('Replying...');
|
||||
msg.replyWithFile(serifs.maze.foryou, file);
|
||||
}, 3000);
|
||||
return {
|
||||
reaction: 'like'
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import * as Line from 'pureimage/src/Line.js';
|
|||
import { CellType } from './maze';
|
||||
import { themes } from './themes';
|
||||
|
||||
const imageSize = 2048; // px
|
||||
const margin = 192;
|
||||
const imageSize = 1024; // px
|
||||
const margin = 96;
|
||||
const mazeAreaSize = imageSize - (margin * 2);
|
||||
|
||||
export function renderMaze(seed, maze: CellType[][], stream: fs.WriteStream): Promise<void> {
|
||||
|
|
|
@ -313,7 +313,8 @@ export default {
|
|||
},
|
||||
|
||||
maze: {
|
||||
post: '今日の迷路です! #AiMaze'
|
||||
post: '今日の迷路です! #AiMaze',
|
||||
foryou: '描きました!'
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue