Skip to content

Commit

Permalink
configure on channel followers notification
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Nov 8, 2024
1 parent 6add517 commit f8d3169
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions handlers/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class Stream {
await TwitchService.setGame(name).catch(() => { console.error('setGame on changeCategory')})
}

async setNotifyChannelFollowMessage(value) {
const valueNumber = parseInt(value)
if (typeof valueNumber === 'number') {
await TwitchService.setNotifyChannelFollowMessage(!!valueNumber).catch(() => { console.error('setNotifyChannelFollowMessage on setNotifyChannelFollowMessage')})
}
}

async getScreenshots(target, bot) {
bot.say(target, `Fotos del stream ${config.externalUrl}/stream`)
}
Expand Down
7 changes: 5 additions & 2 deletions lib/eventSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ class EventSub {
}

async subscribeEvent (channelId) {
this.middleware.onChannelFollow(channelId, config.twitch.userId, event => {
this.middleware.onChannelFollow(channelId, config.twitch.userId, async event => {
console.log(`${event.userDisplayName} just followed ${event.broadcasterDisplayName}!`);
this.bot.say(`#${config.twitch.channels}`, `Gracias por seguirnos @${event.userDisplayName}!`)
const channel = await TwitchService.getChannel()
if (channel.notifyChannelFollowMessage) {
this.bot.say(`#${config.twitch.channels}`, `Gracias por seguirnos @${event.userDisplayName}!`)
}
})

this.middleware.onChannelRedemptionAddForReward(channelId, "427b3e63-e6cd-4d36-8954-9c7198af0a1d", event => {
Expand Down
4 changes: 4 additions & 0 deletions lib/inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class InputParser {
return text.toLowerCase().startsWith('!f5')
}

isAskingToSetOnChannelFollowNotificationMessage (text) {
return text.toLowerCase().startsWith('!followers')
}

isAskingForGetBirthday (text) {
return text.toLowerCase().startsWith('!cumple')
}
Expand Down
3 changes: 3 additions & 0 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class Messenger {
(isVip(context) ||isMod(context) || isBroadcaster(context)))
return handlers.stream.refreshPage(target, this.bot, this.notifier.bot)

if (textSplit.length > 1 && inputParser.isAskingToSetOnChannelFollowNotificationMessage(textSplit[0]) &&
(isVip(context) ||isMod(context) || isBroadcaster(context)))
return handlers.stream.setNotifyChannelFollowMessage(textSplit[1])

// Bans
if (textSplit.length > 0 && inputParser.isAskingBans(textSplit[0]) &&
Expand Down
5 changes: 5 additions & 0 deletions models/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const ChannelSchema = new Schema({
audioPID: {
type: Number,
required: false
},
notifyChannelFollowMessage: {
type: Boolean,
required: false,
default: true
}
})

Expand Down
7 changes: 6 additions & 1 deletion services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ async function setActiveSpot (activeSpot) {
return dbManager.updateChannel(config.twitch.channels, { activeSpot: activeSpot })
}

async function setNotifyChannelFollowMessage (isActive) {
return dbManager.updateChannel(config.twitch.channels, { notifyChannelFollowMessage: isActive })
}

async function _getHeaders () {
const token = await dbManager.getToken(parseInt(config.twitch.userId)).lean()
return {
Expand Down Expand Up @@ -242,7 +246,8 @@ module.exports = {
getBannedUsersCountByDate,
getTimeouts,
removeBan,
getCurrentUsers
getCurrentUsers,
setNotifyChannelFollowMessage
}


0 comments on commit f8d3169

Please sign in to comment.