mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 13:17:59 +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 connection: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ローカルタイムラインストリーム
|
||||||
|
*/
|
||||||
|
private localTimelineConnection: any;
|
||||||
|
|
||||||
private modules: IModule[] = [];
|
private modules: IModule[] = [];
|
||||||
|
|
||||||
constructor(account: any) {
|
constructor(account: any) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
|
||||||
|
//#region Home stream
|
||||||
this.connection = new ReconnectingWebSocket(`${config.wsUrl}/?i=${config.i}`, [], {
|
this.connection = new ReconnectingWebSocket(`${config.wsUrl}/?i=${config.i}`, [], {
|
||||||
WebSocket: WebSocket
|
WebSocket: WebSocket
|
||||||
});
|
});
|
||||||
|
@ -42,9 +48,27 @@ export default class 藍 {
|
||||||
|
|
||||||
this.onMessage(msg);
|
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) => {
|
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) => {
|
private onMention = (msg: MessageLike) => {
|
||||||
console.log(`mention received: ${msg.id}`);
|
console.log(`mention received: ${msg.id}`);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import EmojiModule from './modules/emoji';
|
||||||
import FortuneModule from './modules/fortune';
|
import FortuneModule from './modules/fortune';
|
||||||
import GuessingGameModule from './modules/guessing-game';
|
import GuessingGameModule from './modules/guessing-game';
|
||||||
import KeywordModule from './modules/keyword';
|
import KeywordModule from './modules/keyword';
|
||||||
|
import WelcomeModule from './modules/welcome';
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
const promiseRetry = require('promise-retry');
|
const promiseRetry = require('promise-retry');
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ promiseRetry(retry => {
|
||||||
const ai = new 藍(account);
|
const ai = new 藍(account);
|
||||||
|
|
||||||
ai.install(new PingModule());
|
ai.install(new PingModule());
|
||||||
|
ai.install(new WelcomeModule());
|
||||||
ai.install(new EmojiModule());
|
ai.install(new EmojiModule());
|
||||||
ai.install(new FortuneModule());
|
ai.install(new FortuneModule());
|
||||||
ai.install(new GuessingGameModule());
|
ai.install(new GuessingGameModule());
|
||||||
|
|
|
@ -5,5 +5,6 @@ export default interface IModule {
|
||||||
name: string;
|
name: string;
|
||||||
install?: (ai: 藍) => void;
|
install?: (ai: 藍) => void;
|
||||||
onMention?: (msg: MessageLike) => boolean;
|
onMention?: (msg: MessageLike) => boolean;
|
||||||
|
onLocalNote?: (note: any) => void;
|
||||||
onReplyThisModule?: (msg: MessageLike) => 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