Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #2

Merged
merged 12 commits into from
Oct 18, 2017
Merged
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
build
typings
lib
src/**/*.js
example
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このあたりも今まで動いてたのが謎

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ms from 'ms';
import ms = require('ms');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

かなしい

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));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where が type predicate として振る舞わないので泣く泣くこうしている (isInstantMessage も同様)

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは元の実装がおかしかった疑惑がある.

}

export function updateUser(key: string, project: (x: User) => User): Action {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
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.

Loading