Skip to content

Commit

Permalink
Merge pull request #6 from DogeHQ/dev
Browse files Browse the repository at this point in the history
chore(deploy): Merge dev -> main
  • Loading branch information
Yoshida Tomio authored May 3, 2021
2 parents 80d99c1 + a83f2fb commit 24b6c9a
Show file tree
Hide file tree
Showing 28 changed files with 1,825 additions and 123 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: 'marine/prettier/node',
root: true,
rules: {
'valid-jsdoc': 'error',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'no-return-await': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
},
};
11 changes: 0 additions & 11 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [ main, dev ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [ main, dev ]
schedule:
- cron: '0 */2 * * *'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
lint:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ typings/
public/
.github/workflows
.yarn/
.github/dependabot.yml
.yarnrc.yml
9 changes: 0 additions & 9 deletions .prettierrc.json

This file was deleted.

12 changes: 6 additions & 6 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-berry.cjs
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:buster

WORKDIR /dogehq

COPY . /dogehq

RUN ls -la /dogehq && \
yarn && \
npm i -g http-server && \
yarn docs

COPY . .

CMD ["http-server", "./public", "--port ${PORT-8000}"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
<p>
<a href="https://www.npmjs.com/package/dogehq"><img src="https://img.shields.io/npm/v/dogehq.svg?maxAge=3600" alt="NPM version" /></a>
<a href="https://www.npmjs.com/package/dogehq"><img src="https://img.shields.io/npm/dt/dogehq?maxAge=3600" alt="NPM downloads" /></a>
<a href="https://david-dm.org/Shukaaku/dogehq"><img src="https://david-dm.org/Shukaaku/dogehq/status.svg?maxAge=3600" alt="Dependencies" /></a>
<a href="https://david-dm.org"><img src="https://david-dm.org/DogeHQ/dogehq.svg" alt="Dependencies" /></a>
<a href="https://david-dm.org"><img src="https://david-dm.org/DogeHQ/dogehq/dev-status.svg" alt="Dev Dependencies" /></a>
<a href="https://prettier.io"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" alt="Prettier" /></a>
<a href="https://renovatebot.com"><img src="https://img.shields.io/badge/renovate-enabled-brightgreen.svg" alt="Renovate" /></a>
<br />
<a href="https://github.com/DogeHQ/dogehq"><img src="https://github.com/DogeHQ/dogehq/actions/workflows/lint.yml/badge.svg" alt="ESLint" /></a>
<a href="https://github.com/DogeHQ/dogehq"><img src="https://github.com/DogeHQ/dogehq/actions/workflows/docs.yml/badge.svg" alt="Docs" /></a>
<a href="https://github.com/DogeHQ/dogehq"><img src="https://github.com/DogeHQ/dogehq/actions/workflows/codeql-analysis.yml/badge.svg" alt="CodeQL" /></a>
</p>
<p>
<a href="https://nodei.co/npm/dogehq/"><img src="https://nodei.co/npm/dogehq.png?downloads=true&stars=true" alt="NPM info" /></a>
Expand Down
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
46 changes: 28 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dogehq",
"version": "1.6.1",
"version": "1.7.0",
"description": "A wrapper for the DogeHouse Kebab API Client.",
"main": "./dist/index.js",
"types": "./dist/",
Expand All @@ -26,32 +26,42 @@
},
"license": "Apache-2.0",
"scripts": {
"docs": "rimraf public && typedoc",
"docs": "rimraf public && typedoc --options typedoc.json",
"build": "tsc",
"lint": "eslint . --fix",
"prettier": "prettier . --write",
"test": "node test/index.js"
"test": "node test/index.js",
"postinstall": "husky install",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable",
"merge": "git pull origin dev && git add . && git commit -m \"chore(deploy): Merge dev -> main\" && git checkout main && git merge dev && git push origin main --force && git checkout dev"
},
"files": [
"dist"
],
"dependencies": {
"@dogehouse/kebab": "^0.2.8",
"eventemitter3": "^4.0.7"
"@dogehouse/kebab": "^0.3.0",
"eventemitter3": "^4.0.7",
"make-promises-safe": "^5.1.0"
},
"devDependencies": {
"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-marine": "^8.3.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"tslib": "^2.2.0",
"typedoc": "^0.20.36",
"typedoc-plugin-pages-fork": "^0.0.1",
"typescript": "^4.2.4"
"@commitlint/cli": "12.1.2",
"@commitlint/config-conventional": "12.1.2",
"@commitlint/prompt-cli": "12.1.2",
"@types/jest": "26.0.23",
"@types/node": "15.0.1",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
"eslint": "7.25.0",
"eslint-config-marine": "8.3.2",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "3.4.0",
"husky": "6.0.0",
"pinst": "2.1.6",
"prettier": "2.2.1",
"rimraf": "3.0.2",
"typedoc": "0.20.36",
"typedoc-plugin-pages-fork": "0.0.1",
"typescript": "4.2.4"
}
}
9 changes: 9 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
printWidth: 120,
useTabs: true,
singleQuote: true,
quoteProps: 'as-needed',
trailingComma: 'all',
endOfLine: 'lf',
tabWidth: 8,
};
3 changes: 3 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["config:base"]
}
29 changes: 25 additions & 4 deletions src/Structures/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { TypedEventEmitter } from '../Util/TypedEmitter';
import { baseUrl } from '../Util/Constants';
import { Collection } from './Collection';
import { ClientUser } from './ClientUser';
import { Message } from './Message';
import EventEmitter from 'eventemitter3';
import { Message } from './Message';
import { Room } from './Room';
import { User } from './User';

Expand All @@ -20,6 +20,11 @@ export interface BotCredentials {
username: string;
}

export interface ClientOptions {
apiUrl?: string;
fetchTimeout?: number;
}

export interface ClientEvents {
ready: () => void;
userJoin: (user?: User) => void;
Expand All @@ -31,11 +36,14 @@ export interface ClientEvents {
leaveRoom: (room: Room) => void;
raw: (data: string) => void;
error: (error: Error) => void;
speakerAdd: (user?: User) => void;
speakerRemove: (user?: User) => void;
}

/**
* The main client class.
* @extends {EventEmitter}
* @param {ClientOptions|undefined} options - The client options.
* @example ```js
* const { Client } = require('dogehq');
* const client = new Client();
Expand Down Expand Up @@ -64,6 +72,12 @@ export class Client extends ((EventEmitter as any) as new () => TypedEventEmitte
*/
private readonly _immediates = new Set<NodeJS.Immediate>();

/**
* The client options that you set.
* @type {ClientOptions}
*/
private readonly _options?: ClientOptions;

/**
* The raw connection.
* @type {raw.Connection}
Expand Down Expand Up @@ -106,8 +120,10 @@ export class Client extends ((EventEmitter as any) as new () => TypedEventEmitte
*/
public user!: ClientUser | null;

public constructor() {
public constructor(options?: ClientOptions) {
super();

this._options = options;
}

/**
Expand Down Expand Up @@ -136,7 +152,8 @@ export class Client extends ((EventEmitter as any) as new () => TypedEventEmitte
this.emit('error', err);
throw err;
},
url: baseUrl,
url: this._options?.apiUrl ?? baseUrl,
fetchTimeout: this._options?.fetchTimeout,
});
this.user = new ClientUser(this);
this.rooms = new Collection<string, Room>();
Expand All @@ -154,7 +171,11 @@ export class Client extends ((EventEmitter as any) as new () => TypedEventEmitte
this.emit('userLeave', this.users.get(userId), this.rooms.get(roomId)),
);
this.wrapper.subscribe.handRaised(({ userId }) => this.emit('handRaised', this.users.get(userId)));
this.wrapper.subscribe.invitationToRoom(async (data) => await this.emit('invite', data));
this.wrapper.subscribe.invitationToRoom((data) => this.emit('invite', data));
this.wrapper.subscribe.speakerAdded(({ userId }) => this.emit('speakerAdd', this.users.get(userId)));
this.wrapper.subscribe.speakerRemoved(({ userId }) =>
this.emit('speakerRemove', this.users.get(userId)),
);
this.token = token;
this.refreshToken = refreshToken;

Expand Down
10 changes: 6 additions & 4 deletions src/Structures/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Message as MessageInfo, tokensToString, stringToToken } from '@dogehouse/kebab';
import { Message as MessageInfo, tokensToString } from '@dogehouse/kebab';
import { toMention, toString } from '../Util/MessageBuilder';
import { User, UUID } from './User';
import { Client } from './Client';

Expand Down Expand Up @@ -80,9 +81,10 @@ export class Message {
* @param {string} content - The content.
*/
public async reply(content: string): Promise<void> {
await this.client.wrapper.mutation.sendRoomChatMsg(
stringToToken(`@${this.author.displayName} , ${content}`),
);
await this.client.wrapper.mutation.sendRoomChatMsg([
toMention(`@${this.author.username}`),
toString(`, ${content}`),
]);
}

/**
Expand Down
26 changes: 20 additions & 6 deletions src/Structures/Room.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stringToToken, Room as RoomInfo, JoinRoomAndGetInfoResponse } from '@dogehouse/kebab';
import { Room as RoomInfo, JoinRoomAndGetInfoResponse, CurrentRoom, MessageToken } from '@dogehouse/kebab';
import { Collection } from './Collection';
import { User, UUID } from './User';
import { Client } from './Client';
import { User } from './User';

export type PeoplePreview = Array<{
id: string;
Expand Down Expand Up @@ -83,6 +83,18 @@ export class Room {
*/
public users: Collection<string, User>;

/**
* The list of muted users.
* @type {Record<UUID, boolean>}
*/
public mutes: Record<UUID, boolean>;

/**
* The list of deafened users.
* @type {Record<UUID, boolean>}
*/
public deafs: Record<UUID, boolean>;

public constructor(client: Client, room: RoomInfo) {
this.client = client;

Expand All @@ -96,17 +108,19 @@ export class Room {
this.creatorId = room.creatorId;
this.insertedAt = room.inserted_at;
this.users = new Collection();
this.mutes = (client.user?.currentRoom as CurrentRoom).muteMap;
this.deafs = (client.user?.currentRoom as CurrentRoom).deafMap;

void this._setUsers();
this._setUsers();
}

/**
* Sends a message to the room.
* @param {string} message - The message you wanna send.
* @param {MessageToken[]} tokens - The message tokens.
* @param {string[]} [whisperedTo] - An array of usernames to whisper.
*/
public async send(message: string, whisperedTo?: string[]): Promise<void> {
await this.client.wrapper.mutation.sendRoomChatMsg(stringToToken(message), whisperedTo);
public async send(tokens: MessageToken[], whisperedTo?: string[]): Promise<void> {
await this.client.wrapper.mutation.sendRoomChatMsg(tokens, whisperedTo);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Structures/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User as UserInfo, Room as RoomInfo, RoomUser } from '@dogehouse/kebab';
import { User as UserInfo, RoomUser, Room as RoomInfo } from '@dogehouse/kebab';
import { Client } from './Client';

export type UUID = string;
Expand Down
Loading

0 comments on commit 24b6c9a

Please sign in to comment.