mirror of
https://github.com/nullnyat/NullcatChan.git
synced 2025-08-05 12:13:54 +09:00
数当てゲームを実装するなど
This commit is contained in:
@ -119,10 +119,12 @@ const faces = [
|
||||
]
|
||||
|
||||
export default class EmojiModule implements IModule {
|
||||
public name = 'emoji';
|
||||
|
||||
public install = (ai: 藍) => { }
|
||||
|
||||
public onMention = (msg: MessageLike) => {
|
||||
if (msg.text && msg.text.includes('絵文字')) {
|
||||
if (msg.text && (msg.text.includes('絵文字') || msg.text.includes('emoji'))) {
|
||||
const hand = hands[Math.floor(Math.random() * hands.length)];
|
||||
const face = faces[Math.floor(Math.random() * faces.length)];
|
||||
const emoji = Array.isArray(hand) ? hand[0] + face + hand[1] : hand + face + hand;
|
||||
|
@ -24,7 +24,9 @@ const items = [
|
||||
'寿司'
|
||||
];
|
||||
|
||||
export default class EmojiModule implements IModule {
|
||||
export default class FortuneModule implements IModule {
|
||||
public name = 'fortune';
|
||||
|
||||
public install = (ai: 藍) => { }
|
||||
|
||||
public onMention = (msg: MessageLike) => {
|
||||
|
118
src/modules/guessing-game/index.ts
Normal file
118
src/modules/guessing-game/index.ts
Normal file
@ -0,0 +1,118 @@
|
||||
import 藍 from '../../ai';
|
||||
import IModule from '../../module';
|
||||
import MessageLike from '../../message-like';
|
||||
import serifs from '../../serifs';
|
||||
import db from '../../memory';
|
||||
|
||||
export const guesses = db.addCollection<{
|
||||
userId: string;
|
||||
secret: number;
|
||||
tries: number[];
|
||||
isEnded: boolean;
|
||||
startedAt: number;
|
||||
endedAt: number;
|
||||
}>('guessingGame', {
|
||||
indices: ['userId']
|
||||
});
|
||||
|
||||
export default class GuessingGameModule implements IModule {
|
||||
public name = 'guessingGame';
|
||||
private ai: 藍;
|
||||
|
||||
public install = (ai: 藍) => {
|
||||
this.ai = ai;
|
||||
}
|
||||
|
||||
public onMention = (msg: MessageLike) => {
|
||||
if (msg.text && msg.text.includes('数当て')) {
|
||||
const exist = guesses.findOne({
|
||||
userId: msg.userId,
|
||||
isEnded: false
|
||||
});
|
||||
|
||||
if (exist != null) {
|
||||
msg.reply(serifs.GUESSINGGAME_ARLEADY_STARTED);
|
||||
} else {
|
||||
const secret = Math.floor(Math.random() * 100);
|
||||
|
||||
guesses.insertOne({
|
||||
userId: msg.userId,
|
||||
secret: secret,
|
||||
tries: [],
|
||||
isEnded: false,
|
||||
startedAt: Date.now(),
|
||||
endedAt: null
|
||||
});
|
||||
|
||||
msg.reply(serifs.GUESSINGGAME_STARTED).then(reply => {
|
||||
this.ai.subscribeReply(this, msg.userId, msg.isMessage, msg.isMessage ? msg.userId : reply.id);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public onReplyThisModule = (msg: MessageLike) => {
|
||||
if (msg.text == null) return;
|
||||
|
||||
const exist = guesses.findOne({
|
||||
userId: msg.userId,
|
||||
isEnded: false
|
||||
});
|
||||
|
||||
if (msg.text.includes('やめ')) {
|
||||
msg.reply(serifs.GUESSINGGAME_CANCEL);
|
||||
exist.isEnded = true;
|
||||
exist.endedAt = Date.now();
|
||||
guesses.update(exist);
|
||||
this.ai.unsubscribeReply(this, msg.userId);
|
||||
return;
|
||||
}
|
||||
|
||||
const guess = msg.text.toLowerCase().replace(this.ai.account.username.toLowerCase(), '').match(/[0-9]+/);
|
||||
|
||||
if (guess == null) {
|
||||
msg.reply(serifs.GUESSINGGAME_NAN).then(reply => {
|
||||
this.ai.subscribeReply(this, msg.userId, msg.isMessage, reply.id);
|
||||
});
|
||||
} else {
|
||||
const g = parseInt(guess, 10);
|
||||
|
||||
const firsttime = exist.tries.indexOf(g) === -1;
|
||||
|
||||
let text: string;
|
||||
let end = false;
|
||||
|
||||
if (exist.secret < g) {
|
||||
text = firsttime
|
||||
? serifs.GUESSINGGAME_LESS.replace('$', g.toString())
|
||||
: serifs.GUESSINGGAME_LESS_AGAIN.replace('$', g.toString());
|
||||
} else if (exist.secret > g) {
|
||||
text = firsttime
|
||||
? serifs.GUESSINGGAME_GRATER.replace('$', g.toString())
|
||||
: serifs.GUESSINGGAME_GRATER_AGAIN.replace('$', g.toString());
|
||||
} else {
|
||||
end = true;
|
||||
text = serifs.GUESSINGGAME_CONGRATS.replace('{tries}', exist.tries.length.toString());
|
||||
}
|
||||
|
||||
if (end) {
|
||||
exist.isEnded = true;
|
||||
exist.endedAt = Date.now();
|
||||
guesses.update(exist);
|
||||
this.ai.unsubscribeReply(this, msg.userId);
|
||||
} else {
|
||||
exist.tries.push(g);
|
||||
guesses.update(exist);
|
||||
}
|
||||
|
||||
msg.reply(text).then(reply => {
|
||||
if (!end) {
|
||||
this.ai.subscribeReply(this, msg.userId, msg.isMessage, reply.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ import IModule from '../../module';
|
||||
import MessageLike from '../../message-like';
|
||||
|
||||
export default class PingModule implements IModule {
|
||||
public name = 'ping';
|
||||
|
||||
public install = (ai: 藍) => { }
|
||||
|
||||
public onMention = (msg: MessageLike) => {
|
||||
|
@ -8,6 +8,8 @@ import MessageLike from '../../message-like';
|
||||
import * as WebSocket from 'ws';
|
||||
|
||||
export default class ReversiModule implements IModule {
|
||||
public name = 'reversi';
|
||||
|
||||
private ai: 藍;
|
||||
|
||||
/**
|
||||
@ -38,7 +40,7 @@ export default class ReversiModule implements IModule {
|
||||
}
|
||||
|
||||
public onMention = (msg: MessageLike) => {
|
||||
if (msg.text && msg.text.includes('リバーシ')) {
|
||||
if (msg.text && (msg.text.includes('リバーシ') || msg.text.toLowerCase().includes('reversi'))) {
|
||||
if (config.reversiEnabled) {
|
||||
msg.reply(serifs.REVERSI_OK);
|
||||
|
||||
|
@ -8,6 +8,8 @@ import MessageLike from '../../message-like';
|
||||
const ReconnectingWebSocket = require('../../../node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js');
|
||||
|
||||
export default class ServerModule implements IModule {
|
||||
public name = 'server';
|
||||
|
||||
private ai: 藍;
|
||||
private connection?: any;
|
||||
private preventScheduleReboot = false;
|
||||
|
Reference in New Issue
Block a user