Skip to content

Commit

Permalink
fix: Refactor addInvisible suffix to all channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
KararTY committed Aug 15, 2020
1 parent 233e0ae commit da36ab3
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 58 deletions.
16 changes: 12 additions & 4 deletions src/Handlers/BioHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class BioHandler extends DefaultHandler {
public helpText = () => 'sets your profile bio. Add "global" in the beginning to change your global profile\'s bio.'

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.makeResponseMesage(msg) as BIO
const responseMessage = this.getNameAndIds(msg) as BIO

// Filter bad words.
const message = { ...msg }
Expand All @@ -32,10 +32,18 @@ export default class BioHandler extends DefaultHandler {

if (bioText.length > 1) {
if (bioText.length > 127) {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'your bio is too long. 128 characters max.')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'your bio is too long. 128 characters max.',
)
return
} else if (bioText.length < 3) {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'your bio is too long. 3 minimum characters.')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'your bio is too long. 3 minimum characters.',
)
return
}
}
Expand All @@ -46,7 +54,7 @@ export default class BioHandler extends DefaultHandler {
}

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))
}

private escapeRegExp (text: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/BotHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export default class BotHandler extends DefaultHandler {
}

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.getNameAndIds(msg)
const message = `${String(this.twitch.packageJSON.description)} By N\u{E0000}otKarar. Version: ${String(this.twitch.packageJSON.version)}`

this.twitch.sendMessage(msg.channelName, msg.senderUsername, message)
this.twitch.sendMessage(responseMessage.channelTwitch, responseMessage.userTwitch, message)
}

// public onServerResponse (res) {}
Expand Down
16 changes: 13 additions & 3 deletions src/Handlers/DailyHoroscopeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default class DailyHoroscopeHandler extends DefaultHandler {
private readonly horoscopesDirPath: string = path.join(os.homedir(), 'horoscopes')

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.getNameAndIds(msg)

let horoscopeName = Sign.LE.toString()

if (words[0] !== undefined) {
Expand All @@ -66,7 +68,11 @@ export default class DailyHoroscopeHandler extends DefaultHandler {
if (response !== null) {
fileContent = JSON.stringify(response)
} else {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'no horoscope today! Check back tomorrow?')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'no horoscope today! Check back tomorrow?',
)
return
}
}
Expand All @@ -83,14 +89,18 @@ export default class DailyHoroscopeHandler extends DefaultHandler {
if (response !== null) {
horoscope = response
} else {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'no horoscope today! Check back tomorrow?')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'no horoscope today! Check back tomorrow?',
)
return
}
}

const message = `${horoscope.sign} horoscope for date ${horoscope.date}: ${horoscope.horoscope.split('. ')[0]}...`

this.twitch.sendMessage(msg.channelName, msg.senderUsername, message)
this.twitch.sendMessage(responseMessage.channelTwitch, responseMessage.userTwitch, message)
}

private async requestHoroscope (sign: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/DefaultHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class DefaultHandler {
this.logger = logger
}

public makeResponseMesage (msg: PrivmsgMessage): BASE {
public getNameAndIds (msg: PrivmsgMessage): BASE {
return {
userTwitch: {
name: msg.senderUsername,
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/EmotesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class EmotesHandler extends DefaultHandler {
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.makeResponseMesage(msg) as EMOTES
const responseMessage = this.getNameAndIds(msg) as EMOTES

// TODO: Add FFZ & BTTV emote detections.

Expand All @@ -36,6 +36,6 @@ export default class EmotesHandler extends DefaultHandler {
}

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))
}
}
2 changes: 1 addition & 1 deletion src/Handlers/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class ErrorHandler extends DefaultHandler {
// public async onCommand (msg: PrivmsgMessage) {}

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, result.value)
this.twitch.sendMessage(channelTwitch, userTwitch, result.value)

this.twitch.removeUserInstance({ userTwitch, channelTwitch })
}
Expand Down
4 changes: 3 additions & 1 deletion src/Handlers/HelpHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class HelpHandler extends DefaultHandler {
public helpText = () => 'rubber ducky 🦆 Never lucky.'

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.getNameAndIds(msg)

const commands = this.twitch.handlers.filter(command => !command.adminOnly && command.prefix.length !== 0)

let message: string = ''
Expand All @@ -24,7 +26,7 @@ export default class HelpHandler extends DefaultHandler {
}

if (message.length > 0) {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, message)
this.twitch.sendMessage(responseMessage.channelTwitch, responseMessage.userTwitch, message)
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/Handlers/JoinChatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class JoinChannelHandler extends DefaultHandler {
public adminOnly = true

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.makeResponseMesage(msg) as JOINCHAT
const responseMessage = this.getNameAndIds(msg) as JOINCHAT

// Get user details for provided user.
const res = await this.twitch.api.getUser(this.twitch.token.superSecret, [words[0]])
Expand All @@ -21,7 +21,11 @@ export default class JoinChannelHandler extends DefaultHandler {

this.ws.sendMessage(MessageType.JOINCHAT, JSON.stringify(responseMessage))
} else {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'could not find that user on Twitch.')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
)
}
}

Expand All @@ -40,8 +44,8 @@ export default class JoinChannelHandler extends DefaultHandler {

// if (userTwitch.id.length > 0 && userTwitch.name.length > 0) {
// this.twitch.sendMessage(
// joinUserTwitch.name,
// userTwitch.name,
// joinUserTwitch,
// userTwitch,
// `from channel @${channelTwitch.name}, has added this channel to the service!` +
// 'BeFriendlier.app for more information.`,
// )
Expand Down
12 changes: 8 additions & 4 deletions src/Handlers/LeaveChatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class LeaveChannelHandler extends DefaultHandler {

public async onCommand (msg: PrivmsgMessage, words: string[]) {
// When the bot gets banned, the userTwitch's variables are empty.
const responseMessage = this.makeResponseMesage(msg) as LEAVECHAT
const responseMessage = this.getNameAndIds(msg) as LEAVECHAT

// Get user details for provided user.
const res = await this.twitch.api.getUser(this.twitch.token.superSecret, [words[0]])
Expand All @@ -22,16 +22,20 @@ export default class LeaveChannelHandler extends DefaultHandler {

this.ws.sendMessage(MessageType.LEAVECHAT, JSON.stringify(responseMessage))
} else {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'could not find that user on Twitch.')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
)
}
}

public async onServerResponse ({ channelTwitch, userTwitch, leaveUserTwitch }: LEAVECHAT) {
// When the bot gets banned, it doesn't need to announce that it's leaving, so userTwitch's variables are empty.
if (userTwitch.name.length > 0 && userTwitch.id.length > 0) {
this.twitch.sendMessage(
leaveUserTwitch.name,
userTwitch.name,
leaveUserTwitch,
userTwitch,
`from channel @${channelTwitch.name}, has issued me to leave this channel. FeelsBadMan Good bye!`,
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/MatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class MatchHandler extends DefaultHandler {
public helpText = () => 'attempts to match with the profile.'

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.makeResponseMesage(msg)
const responseMessage = this.getNameAndIds(msg)

const foundUserRoll = this.twitch.getUserInstance(msg)

Expand All @@ -26,7 +26,7 @@ export default class MatchHandler extends DefaultHandler {
}

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/MismatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class MismatchHandler extends DefaultHandler {
// public async onCommand (msg: PrivmsgMessage) {}

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/MoreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class MoreHandler extends DefaultHandler {
public helpText = () => 'returns more information about the rolled profile.'

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.makeResponseMesage(msg) as ROLLMATCH
const responseMessage = this.getNameAndIds(msg) as ROLLMATCH

const foundUserRoll = this.twitch.getUserInstance(msg)

Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/NoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class NoHandler extends DefaultHandler {
public helpText = () => 'will add the rolled profile to your mismatches.'

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.makeResponseMesage(msg)
const responseMessage = this.getNameAndIds(msg)

const foundUserRoll = this.twitch.getUserInstance(msg)

Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/PingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class PingHandler extends DefaultHandler {
public helpText = () => 'returns ping info about Twitch IRC & Website.'

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.makeResponseMesage(msg)
const responseMessage = this.getNameAndIds(msg)

const dateNow = Date.now()
await this.twitch.ircClient.ping()
Expand All @@ -22,8 +22,8 @@ export default class PingHandler extends DefaultHandler {
public async onServerResponse (data: BASE | undefined, res: { timestamp: number }) {
if (data !== undefined) {
this.twitch.sendMessage(
data.channelTwitch.name,
data.userTwitch.name,
data.channelTwitch,
data.userTwitch,
`ping from Bot to Twitch: ~${String(data.result.pingFromBotToTwitch)} ms. ` +
`Ping from Bot to Website roundabout: ~${String(Date.now() - res.timestamp)} ms.`,
)
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/RollMatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class RollMatchHandler extends DefaultHandler {
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.makeResponseMesage(msg) as ROLLMATCH
const responseMessage = this.getNameAndIds(msg) as ROLLMATCH

let foundUserRoll = this.twitch.getUserInstance(msg)

Expand Down Expand Up @@ -42,6 +42,6 @@ export default class RollMatchHandler extends DefaultHandler {
.replace('%prefix%', '@@')
}

this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))
}
}
4 changes: 3 additions & 1 deletion src/Handlers/SayHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class SayHandler extends DefaultHandler {
public adminOnly = true

public async onCommand (msg: PrivmsgMessage, words: string[]) {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, words.join(' '))
const responseMessage = this.getNameAndIds(msg)

this.twitch.sendMessage(responseMessage.channelTwitch, responseMessage.userTwitch, words.join(' '))
}

// public async onServerResponse () {}
Expand Down
10 changes: 5 additions & 5 deletions src/Handlers/SuccessHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ export default class SuccessHandler extends DefaultHandler {
if (result.matchUsername !== undefined) {
// Send to this user.
this.twitch./* TODO: whisper */sendMessage(
/** TODO. REMOVE */channelTwitch.name,
userTwitch.name,
/** TODO. REMOVE */channelTwitch,
userTwitch,
String(result.value).replace('%s%', `@${String(result.matchUsername)}`),
)

// // Send to matched user.
// this.twitch./* TODO: whisper */sendMessage(
// /** TODO. REMOVE */channelTwitch.name,
// result.matchUsername,
// /** TODO. REMOVE */channelTwitch,
// result,
// String(result.value).replace('%s%', `@${String(userTwitch.name)}`),
// )

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
} else {
// This is a general acknowledgement message from the server.
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))
}
}
}
4 changes: 2 additions & 2 deletions src/Handlers/TakeABreakHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default class TakeABreakHandler extends DefaultHandler {

public async onServerResponse ({ channelTwitch, userTwitch, result }: BASE) {
this.twitch.sendMessage(
channelTwitch.name,
userTwitch.name,
channelTwitch,
userTwitch,
result !== undefined && result.value.length > 0
? result.value : 'take a break! You\'re currently on a cooldown period.',
)
Expand Down
10 changes: 7 additions & 3 deletions src/Handlers/UnmatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class UnmatchHandler extends DefaultHandler {
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.makeResponseMesage(msg) as UNMATCH
const responseMessage = this.getNameAndIds(msg) as UNMATCH

// Get user details for provided user.
const res = await this.twitch.api.getUser(this.twitch.token.superSecret, [words[0]])
Expand All @@ -24,11 +24,15 @@ export default class UnmatchHandler extends DefaultHandler {

this.ws.sendMessage(MessageType.UNMATCH, JSON.stringify(responseMessage))
} else {
this.twitch.sendMessage(msg.channelName, msg.senderUsername, 'could not find that user on Twitch.')
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
)
}
}

public async onServerResponse ({ channelTwitch, userTwitch, result }: UNMATCH) {
this.twitch.sendMessage(channelTwitch.name, userTwitch.name, String(result.value))
this.twitch.sendMessage(channelTwitch, userTwitch, String(result.value))
}
}
6 changes: 1 addition & 5 deletions src/Handlers/UnregisteredHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ export default class UnregisteredHandler extends DefaultHandler {
// public async onCommand (msg: PrivmsgMessage) {}

public async onServerResponse ({ channelTwitch, userTwitch }: BASE) {
this.twitch.sendMessage(
channelTwitch.name,
userTwitch.name,
'you\'re not registered! Browse to the website to register.',
)
this.twitch.sendMessage(channelTwitch, userTwitch, 'you\'re not registered! Browse to the website to register.')

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
}
Expand Down
Loading

0 comments on commit da36ab3

Please sign in to comment.