-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(events): Twitch Event * fix(events): generic events * feat(events): add events
- Loading branch information
Showing
15 changed files
with
288 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import { ChatUserstate } from 'tmi.js'; | ||
import { ITwitchService } from '../../services/TwitchService'; | ||
|
||
/** | ||
* Base Command | ||
*/ | ||
export interface ICommand { | ||
Trigger: string; | ||
Action(twitchService: ITwitchService, state: ChatUserstate): void; | ||
} | ||
|
||
/** | ||
* Commands | ||
*/ | ||
export * from './WriterCommand' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { EventType, IEvent, IEventParams } from '.'; | ||
import Handlebars from 'handlebars'; | ||
import { ITwitchService } from '../../services/TwitchService'; | ||
|
||
export class RandomMessageEvent<T extends IEventParams> implements IEvent<T> { | ||
public Type: EventType; | ||
private _messages: Array<string>; | ||
|
||
constructor(type: EventType, messages: Array<string>) | ||
{ | ||
this.Type = type; | ||
this._messages = messages; | ||
} | ||
|
||
protected getMessage() : string { | ||
return this._messages[Math.floor(Math.random() * this._messages.length)]; | ||
} | ||
|
||
public Action(twitchService: ITwitchService, params: T): void { | ||
const message = this.getMessage(); | ||
const Template = Handlebars.compile(message); | ||
twitchService.Write( | ||
Template(params) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ITwitchService } from '../../services/TwitchService'; | ||
|
||
/** | ||
* Event Type | ||
*/ | ||
export enum EventType { | ||
RAIDED = 'raided', | ||
JOIN = 'join', | ||
RESUB = 'resub', | ||
SUBMYSTERYGIFT = 'submysterygift', | ||
SUBGIFT = 'subgift', | ||
SUBSCRIPTION = 'subscription' | ||
} | ||
|
||
/** | ||
* Base Event | ||
*/ | ||
export interface IEvent<T extends IEventParams> { | ||
Type: EventType; | ||
Action(twitchService: ITwitchService, params: T): void; | ||
} | ||
|
||
/** | ||
* Event Params | ||
*/ | ||
export interface IEventParams { | ||
Channel: string; | ||
} | ||
|
||
export class RaidedEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
Viewers: number; | ||
} | ||
|
||
export class JoinEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
} | ||
|
||
export class ResubEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
Months: number; | ||
Message: string; | ||
} | ||
|
||
export class SubGiftEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
StreakMonths: number; | ||
RecipientUsername: string; | ||
GiftCount: number; | ||
} | ||
|
||
export class SubMysteryGiftEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
OfferedSubs: number; | ||
GiftCount: number; | ||
} | ||
|
||
export class SubscriptionEventParams implements IEventParams { | ||
Channel: string; | ||
Username: string; | ||
Message: string; | ||
} | ||
|
||
/** | ||
* Events | ||
*/ | ||
export * from './RandomMessageEvent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import { ITwitchService } from '../../services/TwitchService'; | ||
|
||
/** | ||
* Base Scheduler | ||
*/ | ||
export interface IScheduler { | ||
Id: string; | ||
Minutes: number; | ||
Action(twitchService: ITwitchService): void; | ||
} | ||
|
||
/** | ||
* Schedulers | ||
*/ | ||
export * from './RoundRobinScheduler'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { EventType, IEventParams, ResubEventParams } from '../lib/Events'; | ||
import { JoinEventParams, RaidedEventParams, SubMysteryGiftEventParams, SubscriptionEventParams } from '../lib/Events'; | ||
|
||
/** | ||
* Convert tmi.js args to EventTypeParams T | ||
* https://github.com/tmijs/docs/blob/gh-pages/_posts/v1.4.2/2019-03-03-Events.md | ||
* @param eventType | ||
* @param args | ||
* @returns T | ||
*/ | ||
export function EventTypeParamsMapper<T extends IEventParams>(eventType: EventType, args: any[]): T { | ||
let params = { | ||
Channel: args[0] as string | ||
}; | ||
|
||
switch (eventType) { | ||
case EventType.JOIN: | ||
params = Object.assign(params, { | ||
Username: args[1] as string | ||
} as JoinEventParams); | ||
break; | ||
case EventType.RAIDED: | ||
params = Object.assign(params, { | ||
Username: args[1] as string, | ||
Viewers: args[2] as number | ||
} as RaidedEventParams); | ||
break; | ||
case EventType.RESUB: | ||
params = Object.assign(params, { | ||
Username: args[1], | ||
Months: args[2], | ||
Message: args[3] | ||
}) as ResubEventParams; | ||
break; | ||
case EventType.SUBGIFT: | ||
params = Object.assign(params, { | ||
Username: args[1], | ||
StreakMonths: args[2], | ||
RecipientUsername: args[3], | ||
GiftCount: args[5]['msg-param-sender-count'] | ||
}); | ||
break; | ||
case EventType.SUBMYSTERYGIFT: | ||
params = Object.assign(params, { | ||
Username: args[1], | ||
OfferedSubs: args[2], | ||
GiftCount: args[3] | ||
}) as SubMysteryGiftEventParams; | ||
break; | ||
case EventType.SUBSCRIPTION: | ||
params = Object.assign(params, { | ||
Username: args[1], | ||
Message: args[3] | ||
} as SubscriptionEventParams); | ||
break; | ||
} | ||
|
||
return params as T; | ||
} |
Oops, something went wrong.