mirror of
https://github.com/syuilo/ai.git
synced 2024-11-12 17:08:00 +00:00
Add welcome module
This commit is contained in:
parent
05ada0d74e
commit
de72383156
34
src/ai.ts
34
src/ai.ts
|
@ -20,11 +20,17 @@ export default class 藍 {
|
|||
*/
|
||||
private connection: any;
|
||||
|
||||
/**
|
||||
* ローカルタイムラインストリーム
|
||||
*/
|
||||
private localTimelineConnection: any;
|
||||
|
||||
private modules: IModule[] = [];
|
||||
|
||||
constructor(account: any) {
|
||||
this.account = account;
|
||||
|
||||
//#region Home stream
|
||||
this.connection = new ReconnectingWebSocket(`${config.wsUrl}/?i=${config.i}`, [], {
|
||||
WebSocket: WebSocket
|
||||
});
|
||||
|
@ -42,9 +48,27 @@ export default class 藍 {
|
|||
|
||||
this.onMessage(msg);
|
||||
});
|
||||
//#endregion
|
||||
|
||||
if (config.reversiEnabled) {
|
||||
}
|
||||
//#region Local timeline stream
|
||||
this.localTimelineConnection = new ReconnectingWebSocket(`${config.wsUrl}/local-timeline?i=${config.i}`, [], {
|
||||
WebSocket: WebSocket
|
||||
});
|
||||
|
||||
this.localTimelineConnection.addEventListener('open', () => {
|
||||
console.log('local-timeline stream opened');
|
||||
});
|
||||
|
||||
this.localTimelineConnection.addEventListener('close', () => {
|
||||
console.log('local-timeline stream closed');
|
||||
});
|
||||
|
||||
this.localTimelineConnection.addEventListener('message', message => {
|
||||
const msg = JSON.parse(message.data);
|
||||
|
||||
this.onLocalNote(msg.body);
|
||||
});
|
||||
//#endregion
|
||||
}
|
||||
|
||||
public install = (module: IModule) => {
|
||||
|
@ -82,6 +106,12 @@ export default class 藍 {
|
|||
}
|
||||
}
|
||||
|
||||
private onLocalNote = (note: any) => {
|
||||
this.modules.filter(m => m.hasOwnProperty('onLocalNote')).forEach(m => {
|
||||
return m.onLocalNote(note);
|
||||
});
|
||||
}
|
||||
|
||||
private onMention = (msg: MessageLike) => {
|
||||
console.log(`mention received: ${msg.id}`);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import EmojiModule from './modules/emoji';
|
|||
import FortuneModule from './modules/fortune';
|
||||
import GuessingGameModule from './modules/guessing-game';
|
||||
import KeywordModule from './modules/keyword';
|
||||
import WelcomeModule from './modules/welcome';
|
||||
import * as request from 'request-promise-native';
|
||||
const promiseRetry = require('promise-retry');
|
||||
|
||||
|
@ -20,6 +21,7 @@ promiseRetry(retry => {
|
|||
const ai = new 藍(account);
|
||||
|
||||
ai.install(new PingModule());
|
||||
ai.install(new WelcomeModule());
|
||||
ai.install(new EmojiModule());
|
||||
ai.install(new FortuneModule());
|
||||
ai.install(new GuessingGameModule());
|
||||
|
|
|
@ -5,5 +5,6 @@ export default interface IModule {
|
|||
name: string;
|
||||
install?: (ai: 藍) => void;
|
||||
onMention?: (msg: MessageLike) => boolean;
|
||||
onLocalNote?: (note: any) => void;
|
||||
onReplyThisModule?: (msg: MessageLike) => void;
|
||||
}
|
||||
|
|
29
src/modules/welcome/index.ts
Normal file
29
src/modules/welcome/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import 藍 from '../../ai';
|
||||
import IModule from '../../module';
|
||||
|
||||
export default class WelcomeModule implements IModule {
|
||||
public name = 'welcome';
|
||||
|
||||
private ai: 藍;
|
||||
|
||||
public install = (ai: 藍) => {
|
||||
this.ai = ai;
|
||||
}
|
||||
|
||||
public onLocalNote = (note: any) => {
|
||||
if (note.user.notesCount == 1) {
|
||||
setTimeout(() => {
|
||||
this.ai.api('notes/create', {
|
||||
renoteId: note.id
|
||||
});
|
||||
}, 3000);
|
||||
|
||||
setTimeout(() => {
|
||||
this.ai.api('notes/reactions/create', {
|
||||
noteId: note.id,
|
||||
reaction: 'congrats'
|
||||
});
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue