Skip to content

Commit

Permalink
Merge pull request #2 from hiroqn/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
ryota-ka committed Oct 18, 2017
2 parents efb7440 + 703eeeb commit 5e73b16
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 1,000 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,6 +1,5 @@
node_modules
build
typings
lib
src/**/*.js
example
16 changes: 9 additions & 7 deletions package.json
Expand Up @@ -10,15 +10,17 @@
"url": "https://github.com/hiroqn/cyclebot/issues"
},
"dependencies": {
"ms": "^0.7.3",
"ramda": "^0.22.1",
"rxjs": "^5.0.2",
"ws": "^1.1.1"
"ms": "^2.0.0",
"ramda": "^0.25.0",
"rxjs": "^5.4.3",
"ws": "^3.2.0"
},
"devDependencies": {
"@types/ramda": "ts2.1",
"typescript": "^2.1.4",
"typings": "^2.0.0"
"@types/ms": "^0.7.30",
"@types/node": "^8.0.44",
"@types/ramda": "^0.24.17",
"@types/ws": "^3.2.0",
"typescript": "^2.5.2"
},
"files": [
"src",
Expand Down
13 changes: 8 additions & 5 deletions src/event-source.ts
Expand Up @@ -3,14 +3,17 @@ import {Status, PartialStatus} from './state/status';
import {empty} from 'rxjs/observable/empty';
import {of} from 'rxjs/observable/of';
import {IncomingMessage} from './state/message';
import {Channel} from './state/channel';
import {InstantMessage} from './state/ims';
import {Channel, isChannel} from './state/channel';
import {InstantMessage, isInstantMessage} from './state/ims';
import {findOne} from './util/map'
type O<T> = Observable<T>;
type BothPS = PartialStatus<IncomingMessage<Channel> | IncomingMessage<InstantMessage>>;
type ChanPS = PartialStatus<IncomingMessage<Channel>>;
type IMPS = PartialStatus<IncomingMessage<InstantMessage>>;

export class EventSource {

private _message$: O<PartialStatus<IncomingMessage<Channel> | IncomingMessage<InstantMessage>>>;
private _message$: O<BothPS>;

constructor(_status$: Observable<Status>) {
const [, message$] = _status$.partition(status => typeof status.event === 'string');
Expand All @@ -19,7 +22,7 @@ export class EventSource {
}

selectByChannelName(name: string): Observable<IncomingMessage<Channel>> {
return this._message$.mergeMap(({event, channels}) => {
return this._message$.filter<BothPS, ChanPS>((ps: BothPS): ps is ChanPS => isChannel(ps.event.channel)).mergeMap(({event, channels}) => {
const channel = findOne(channel => name === channel.name, channels);
if (channel && !event.user.is_bot) {
return of(event);
Expand All @@ -30,7 +33,7 @@ export class EventSource {
}

selectByUserName(name: string): Observable<IncomingMessage<InstantMessage>> {
return this._message$.mergeMap(({users, event, ims}) => {
return this._message$.filter<BothPS, IMPS>((ps: BothPS): ps is IMPS => isInstantMessage(ps.event.channel)).mergeMap(({users, event, ims}) => {
const user = findOne(user => name === user.name, users);
if (!user) {
return empty();
Expand Down
4 changes: 2 additions & 2 deletions src/make-slack-bot-driver.ts
@@ -1,4 +1,4 @@
import * as ms from 'ms';
import ms = require('ms');
import * as WebSocket from 'ws';
import {contains} from 'ramda';
/**
Expand Down Expand Up @@ -78,7 +78,7 @@ export function makeSlackBotDriver(token: string, options?: makeBotDriverOptions
const pong$: O<Timestamp<{}>> = fromEvent(socket, 'pong')
.timestamp();

const pingOutput$ = ping$.mapTo(() => socket.ping(null, {}, true));
const pingOutput$ = ping$.mapTo(() => socket.ping(null, true, true));
const pongOutput$ = fromEvent(socket, 'ping').mapTo(() => socket.pong());
const terminateOutput$ = ping$.withLatestFrom(pong$, (ping, pong) => ping.timestamp - pong.timestamp)
.filter(diff => diff > pingInterval * (pingRetryLimit - 0.5))
Expand Down
20 changes: 11 additions & 9 deletions src/state/channel.ts
@@ -1,4 +1,4 @@
import {where, is, pick, assoc} from 'ramda';
import {pick, assoc} from 'ramda';

export type Channel = {
id: string;
Expand All @@ -9,14 +9,16 @@ export type Channel = {
creator: string;
}

export const isChannel = where({
id: is(String),
name: is(String),
is_member: is(Boolean),
is_archived: is(Boolean),
created: is(Number),
creator: is(String)
});
export function isChannel(x: any): x is Channel {
return typeof x === 'object' &&
x !== null &&
typeof x.id === 'string' &&
typeof x.name === 'string' &&
typeof x.is_member === 'boolean' &&
typeof x.is_archived === 'boolean' &&
typeof x.created === 'number' &&
typeof x.creator === 'string';
};

const channelKeyList: Array<keyof Channel> = [
'id',
Expand Down
16 changes: 9 additions & 7 deletions src/state/ims.ts
@@ -1,4 +1,4 @@
import {where, is, pick} from 'ramda';
import {pick} from 'ramda';

export type InstantMessage = {
id: string;
Expand All @@ -7,12 +7,14 @@ export type InstantMessage = {
created: number;
}

export const isInstantMessage = where({
id: is(String),
user: is(String),
is_open: is(Boolean),
created: is(Number)
});
export function isInstantMessage(x: any): x is InstantMessage {
return typeof x === 'object' &&
x !== null &&
typeof x.id === 'string' &&
typeof x.user === 'string' &&
typeof x.is_open === 'boolean' &&
typeof x.created === 'number';
};

const imKeyList: Array<keyof InstantMessage> = [
'id',
Expand Down
2 changes: 1 addition & 1 deletion src/state/status.ts
Expand Up @@ -53,7 +53,7 @@ export function updateChannel(key: string, project: (x: Channel) => Channel): Ac
}

export function deleteChannel(key: string): Action {
return curryDel(key);
return over(lensProp('channels'), curryDel(key));
}

export function updateUser(key: string, project: (x: User) => User): Action {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Expand Up @@ -17,7 +17,6 @@
"sourceMap": true
},
"include": [
"src/**/*.ts",
"typings/index.d.ts"
"src/**/*.ts"
]
}
11 changes: 0 additions & 11 deletions typings.json

This file was deleted.

0 comments on commit 5e73b16

Please sign in to comment.