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

[V2] Notice Event #358

Open
wants to merge 3 commits into
base: old-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ typings/
# DynamoDB Local files
.dynamodb/

# Jetbrains Configuration
.idea/*
!.idea/codeStyles

# Specific to the tmi.js project

Expand Down
57 changes: 57 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
GlobalUserStateEvent,
JoinEvent,
PartEvent,
UserStateEvent
UserStateEvent,
NoticeEvent
} from './types';
import { Channel, DummyChannel } from './channel';
import { MessageData, ChatMessage } from './message';
Expand Down Expand Up @@ -84,6 +85,10 @@ export interface Client {
* Received a ROOMSTATE command.
*/
on(event: 'roomstate', listener: (data: MessageData) => void): this;
/**
* Received a NOTICE command.
*/
on(event: 'notice', listener: (data: NoticeEvent) => void): this;

emit(event: string, ...data: any);
emit(event: 'error', error: Error);
Expand All @@ -94,6 +99,7 @@ export interface Client {
emit(event: 'part', data: PartEvent);
emit(event: 'globaluserstate', data: GlobalUserStateEvent);
emit(event: 'roomstate', data: MessageData);
emit(event: 'notice', data: NoticeEvent);
}

export class Client extends EventEmitter {
Expand Down Expand Up @@ -295,6 +301,11 @@ export class Client extends EventEmitter {
this.user = new ClientUser(this, name, tags);
this.emit('globaluserstate', { user: this.user });
}
else if(command === 'NOTICE') {
this.emit('notice', {
message: data.trailing
});
}
else {
this.emit('unhandled-command', data);
}
Expand Down
14 changes: 12 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ export interface JoinEvent {
*/
export interface PartEvent {
/**
* The channel that the user joined.
* The channel that the user parted.
*/
channel: Channel;
/**
* A user or the client user that joined the channel.
* A user or the client user that parted the channel.
*/
user: UserOrClientUser;
}
Expand All @@ -155,4 +155,14 @@ export interface UserStateEvent {
* The user state that was created or updated with this event.
*/
state: UserState;
}

/**
* Received a NOTICE command.
*/
export interface NoticeEvent {
/**
* The message.
*/
message: string;
}