mirror of
https://github.com/syuilo/ai.git
synced 2025-03-25 21:12:56 +00:00
ねこ召喚
This commit is contained in:
parent
9358a91f50
commit
c74c709ae9
3 changed files with 64 additions and 4 deletions
|
@ -15,6 +15,7 @@ import CoreModule from './modules/core';
|
||||||
import TalkModule from './modules/talk';
|
import TalkModule from './modules/talk';
|
||||||
import BirthdayModule from './modules/birthday';
|
import BirthdayModule from './modules/birthday';
|
||||||
import ReversiModule from './modules/reversi';
|
import ReversiModule from './modules/reversi';
|
||||||
|
import summonCat from './modules/summonCat';
|
||||||
import PingModule from './modules/ping';
|
import PingModule from './modules/ping';
|
||||||
import EmojiModule from './modules/emoji';
|
import EmojiModule from './modules/emoji';
|
||||||
import EmojiReactModule from './modules/emoji-react';
|
import EmojiReactModule from './modules/emoji-react';
|
||||||
|
@ -69,6 +70,7 @@ promiseRetry(retry => {
|
||||||
// 藍起動
|
// 藍起動
|
||||||
new 藍(account, [
|
new 藍(account, [
|
||||||
new CoreModule(),
|
new CoreModule(),
|
||||||
|
new summonCat(),
|
||||||
new EmojiModule(),
|
new EmojiModule(),
|
||||||
new EmojiReactModule(),
|
new EmojiReactModule(),
|
||||||
new FortuneModule(),
|
new FortuneModule(),
|
||||||
|
|
|
@ -38,19 +38,19 @@ export default class extends Module {
|
||||||
|
|
||||||
// /う[〜|ー]*んこ/g]にマッチしたときの処理
|
// /う[〜|ー]*んこ/g]にマッチしたときの処理
|
||||||
if (note.text.match(/う[〜|ー]*んこ/g) || includes(note.text, ['unko'])) {
|
if (note.text.match(/う[〜|ー]*んこ/g) || includes(note.text, ['unko'])) {
|
||||||
await react(':anataima_unkotte_iimashitane:', true);
|
await react(':anataima_unkotte_iimashitane:');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.text.match(/う[〜|ー]*んち/g)) {
|
if (note.text.match(/う[〜|ー]*んち/g)) {
|
||||||
await react(':erait:', true);
|
await react(':erait:');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) {
|
if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) {
|
||||||
// 50%の確率で":dame:"または":yattare:"を返す
|
// 50%の確率で":dame:"または":yattare:"を返す
|
||||||
if (Math.random() < 0.5) {
|
if (Math.random() < 0.5) {
|
||||||
return react(':dame:', true);
|
return react(':dame:');
|
||||||
} else {
|
} else {
|
||||||
return react(':yattare:', true);
|
return react(':yattare:');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
58
src/modules/summonCat/index.ts
Normal file
58
src/modules/summonCat/index.ts
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import autobind from 'autobind-decorator';
|
||||||
|
import Module from '@/module';
|
||||||
|
import Message from '@/message';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
import { ReadStream } from 'fs';
|
||||||
|
|
||||||
|
export default class extends Module {
|
||||||
|
public readonly name = 'summonCat';
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
public install() {
|
||||||
|
return {
|
||||||
|
mentionHook: this.mentionHook
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
private async mentionHook(msg: Message) {
|
||||||
|
// cat/Cat/ねこ/ネコ/にゃん
|
||||||
|
console.log(msg.text)
|
||||||
|
if (msg.text && (msg.text.match(/(cat|Cat|ねこ|ネコ|にゃ[〜|ー]*ん)/g))) {
|
||||||
|
const message = "にゃ~ん!";
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
const file = await this.getCatImage();
|
||||||
|
this.log(file);
|
||||||
|
this.log('Replying...');
|
||||||
|
msg.reply(message, { file });
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
return {
|
||||||
|
reaction: ':blobcatmeltnomblobcatmelt:'
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
private async getCatImage(): Promise<any> {
|
||||||
|
// https://aws.random.cat/meowにGETリクエストを送る
|
||||||
|
// fileに画像URLが返ってくる
|
||||||
|
const res = await fetch('https://aws.random.cat/meow');
|
||||||
|
const json = await res.json();
|
||||||
|
console.table(json);
|
||||||
|
const fileUri = json.file;
|
||||||
|
// 拡張子を取り除く
|
||||||
|
const fileName = fileUri.split('/').pop().split('.')[0];
|
||||||
|
const rawFile = await fetch(fileUri);
|
||||||
|
const imgBuffer = await rawFile.buffer();
|
||||||
|
// 拡張子とcontentTypeを判断する
|
||||||
|
const ext = fileUri.split('.').pop();
|
||||||
|
const file = await this.ai.upload(imgBuffer, {
|
||||||
|
filename: `${fileName}.${ext}`,
|
||||||
|
});
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue