-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `FollowEvent` table to DB * Add `FollowEventHandler` event sub to bot
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 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
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,28 @@ | ||
import { EventSubChannelFollowEvent } from '@twurple/eventsub-base'; | ||
import { inject, injectable } from 'inversify'; | ||
import winston from 'winston'; | ||
import InjectionTypes from '../../dependency-management/types'; | ||
import { FollowEvent, ModeratorEvent } from '../../database'; | ||
|
||
@injectable() | ||
export default class FollowerEventHandler { | ||
constructor( | ||
@inject(InjectionTypes.Logger) private logger: winston.Logger, | ||
) { | ||
} | ||
|
||
/** | ||
* Records the event of a user being added as a moderator to the channel | ||
* @param event Moderator Event | ||
*/ | ||
async follow(event: EventSubChannelFollowEvent): Promise<void> { | ||
return FollowEvent | ||
.follow(event) | ||
.catch((reason: any) => { | ||
this.logger.error(`Unable to store Follow event in DB >> ${reason}`); | ||
}) | ||
.then(() => { | ||
this.logger.info(`User ${event.userDisplayName}: followed ${event.broadcasterDisplayName} on ${(new Date()).toDateString()}`); | ||
}); | ||
} | ||
} |
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,13 +1,15 @@ | ||
import BanEventHandler from './ban-event.handler'; | ||
import ChannelPointEventHandler from './channel-point-event.handler'; | ||
import CheerEventHandler from './cheer-event.handler'; | ||
import FollowerEventHandler from './follow-event.handler'; | ||
import ModeratorEventHandler from './moderator-event.handler'; | ||
import StreamEventHandler from './stream-event.handler'; | ||
|
||
export { | ||
BanEventHandler, | ||
ChannelPointEventHandler, | ||
CheerEventHandler, | ||
FollowerEventHandler, | ||
ModeratorEventHandler, | ||
StreamEventHandler, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { EventSubChannelFollowEvent } from '@twurple/eventsub-base'; | ||
import { Column, DataType, Model, Table } from 'sequelize-typescript'; | ||
|
||
@Table({ | ||
// consider placing this in a schema to | ||
// cover all Event Sub data | ||
// schema: 'EventSubData', | ||
tableName: 'FollowEvent', | ||
paranoid: true, | ||
}) | ||
export default class FollowEvent extends Model { | ||
/** | ||
* The date when the user followed. | ||
*/ | ||
@Column({ | ||
type: DataType.DATE, | ||
}) | ||
followDate: Date; | ||
|
||
/** | ||
* The ID of the broadcaster. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(20), | ||
}) | ||
broadcasterId: string; | ||
|
||
/** | ||
* The name of the broadcaster. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(40), | ||
}) | ||
broadcasterName: string; | ||
|
||
/** | ||
* The display name of the broadcaster. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(40), | ||
}) | ||
broadcasterDisplayName: string; | ||
|
||
/** | ||
* The ID of the following user. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(20), | ||
}) | ||
userId: string; | ||
|
||
/** | ||
* The name of the following user. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(40), | ||
}) | ||
userName: string; | ||
|
||
/** | ||
* The display name of the following user. | ||
*/ | ||
@Column({ | ||
type: DataType.STRING(40), | ||
}) | ||
userDisplayName: string; | ||
|
||
/** | ||
* Records the event of a user following the specific channel (broadcaster) | ||
* @param event Follow Event | ||
* @returns Follow Event Record | ||
*/ | ||
static async follow(event: EventSubChannelFollowEvent): Promise<FollowEvent> { | ||
const record: Partial<FollowEvent> = { | ||
followDate: event.followDate, | ||
broadcasterId: event.broadcasterId, | ||
broadcasterName: event.broadcasterName, | ||
broadcasterDisplayName: event.broadcasterDisplayName, | ||
userId: event.userId, | ||
userName: event.userName, | ||
userDisplayName: event.userDisplayName, | ||
}; | ||
|
||
return this | ||
.create(record); | ||
} | ||
} |
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