Skip to content

Commit

Permalink
feat: Add secret
Browse files Browse the repository at this point in the history
  • Loading branch information
KararTY committed Apr 24, 2022
1 parent 4393067 commit 8d52468
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Handlers/DefaultHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class DefaultHandler {
public messageType = 'DEFAULT'
public prefix: string[] = []
public adminOnly = false
public instantResponse = false

public cachedTwitch = {
nextUpdate: Date.now(),
Expand Down
24 changes: 24 additions & 0 deletions src/Handlers/PajbotAlertHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PrivmsgMessage } from '@kararty/dank-twitch-irc'
import DefaultHandler from './DefaultHandler'

export default class MiscHandler extends DefaultHandler {
public instantResponse = true

private readonly responses = [
'monkaPickle 🚨 I NEED A MEDIC BAG',
'monkaPickle 🚨 JÄVLAR',
'monkaPickle 🚨 VAD FAN I HELVETE',
'monkaPickle 🚨 AHHHHH',
'monkaPickle 🚨 THE ALERT, GO GET IT',
'monkaPickle 🚨 LISTEN UP, THIS IS AN ALERT'
]

public prefix = ['pajaS 🚨 ALERT']

public async onCommand (msg: PrivmsgMessage): Promise<void> {
if (msg.senderUserID === '82008718' && msg.channelID === '11148817') {
const randomResponse = this.responses[Math.floor(Math.random() * this.responses.length)]
void this.twitch.ircClient.say(msg.channelName, randomResponse)
}
}
}
18 changes: 15 additions & 3 deletions src/Twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ export default class Client {

const checkMessages: string[] = []

const pajbotCheck = await this.pajbotAPI.check(foundChannel.name, this.filterMsg(message))
const filteredMessage = this.filterMsg(message)

const pajbotCheck = await this.pajbotAPI.check(foundChannel.name, filteredMessage)
if (pajbotCheck === null) {
checkMessages.push('Banphrase API is offline.')
} else if (pajbotCheck.banned) {
Expand All @@ -253,7 +255,7 @@ export default class Client {
checkMessages.push('(v1) message contains banned phrases.')
}

const pajbot2Check = await this.pajbotAPI.checkVersion2(foundChannel.name, this.filterMsg(message))
const pajbot2Check = await this.pajbotAPI.checkVersion2(foundChannel.name, filteredMessage)
if (pajbot2Check === null) {
checkMessages.push('Banphrase v2 API is offline.')
} else if (pajbot2Check.banned) {
Expand Down Expand Up @@ -343,6 +345,16 @@ export default class Client {
return
}

const filteredMsg = this.filterMsg(msg.messageText)

const foundInstantCommand = this.handlers
.find(command => command.prefix.includes(filteredMsg) && command.instantResponse)

if (foundInstantCommand !== undefined) {
await foundInstantCommand.onCommand({ ...msg, messageText: filteredMsg } as unknown as PrivmsgMessage)
return
}

// TODO: REFACTOR THIS LATER.
if (msg.messageText === `!${this.name}`) {
const msgBot = { ...msg }
Expand All @@ -365,7 +377,7 @@ export default class Client {

if (hasSetCooldown) {
// Message class has a "clientRef" to "this" so it can call clientRef.onMessage().
const m: PrivmsgMessage = { ...msg, messageText: this.filterMsg(msg.messageText) } as unknown as PrivmsgMessage
const m = { ...msg, messageText: filteredMsg } as unknown as PrivmsgMessage
this.msgs.set(msg.messageID, new Message(m, this))
}
}
Expand Down

0 comments on commit 8d52468

Please sign in to comment.