Skip to content

Commit

Permalink
fix: Refactor some static strings to messagesText.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
KararTY committed Aug 18, 2020
1 parent 3123435 commit 95ab939
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 33 deletions.
9 changes: 5 additions & 4 deletions src/Handlers/BioHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { MessageType, BIO, BASE } from 'befriendlier-shared'
import { BASE, BIO, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class BioHandler extends DefaultHandler {
public messageType = MessageType.BIO

public prefix = ['bio']

public helpText = () => 'sets your profile bio. Add "global" in the beginning to change your global profile\'s bio.'
public helpText = () => messagesText.helpText.bio

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.getNameAndIds(msg) as BIO
Expand Down Expand Up @@ -35,14 +36,14 @@ export default class BioHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'your bio is too long. 128 characters max.',
messagesText.bioTooLong,
)
return
} else if (bioText.length < 3) {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'your bio is too long. 3 minimum characters.',
messagesText.bioTooShort,
)
return
}
Expand Down
5 changes: 3 additions & 2 deletions src/Handlers/BotHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class BotHandler extends DefaultHandler {
// public messageType = MessageType

public prefix = ['bot', 'befriendlier']
public prefix = ['bot', `${this.twitch.name}`]

public helpText = () => {
const heapUsed = process.memoryUsage().heapUsed / (1024 * 1024)
return `mem used: ~${heapUsed.toFixed(2)} mibibyte.`
return messagesText.helpText.bot.replace('%s', heapUsed.toFixed(2))
}

public async onCommand (msg: PrivmsgMessage) {
Expand Down
9 changes: 5 additions & 4 deletions src/Handlers/DailyHoroscopeHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { PrivmsgMessage } from 'dank-twitch-irc'
import fs from 'fs'
import path from 'path'
import fetch from 'got'
import os from 'os'
import path from 'path'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

enum Sign {
Expand Down Expand Up @@ -33,7 +34,7 @@ export default class DailyHoroscopeHandler extends DefaultHandler {

public helpText = () => {
const signs = Object.values(Sign).map(sign => String(sign))
return `shows daily horoscope. Available signs: ${signs.join(', ')}.`
return messagesText.helpText.horoscope.replace('%s', signs.join(', '))
}

private readonly horoscopes: Horoscope[] = []
Expand Down Expand Up @@ -71,7 +72,7 @@ export default class DailyHoroscopeHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'no horoscope today! Check back tomorrow?',
messagesText.noHoroscope,
)
return
}
Expand All @@ -92,7 +93,7 @@ export default class DailyHoroscopeHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'no horoscope today! Check back tomorrow?',
messagesText.noHoroscope,
)
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/DefaultHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logger } from '@adonisjs/logger/build/standalone'
import { BASE } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import Client from '../Twitch'
import Ws from '../Ws'

Expand All @@ -13,7 +14,7 @@ export default class DefaultHandler {
public prefix: string[] = []
public adminOnly = false

public helpText = () => 'This command has no help usage.'
public helpText = () => messagesText.helpText.none

constructor (twitch: Client, ws: Ws, logger: Logger) {
this.twitch = twitch
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/EmotesHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageType, EMOTES, BASE } from 'befriendlier-shared'
import { BASE, EMOTES, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class EmotesHandler extends DefaultHandler {
Expand All @@ -8,8 +9,7 @@ export default class EmotesHandler extends DefaultHandler {
public prefix = ['emotes']

public helpText = () => {
return 'sets your favorite emotes for your profile. ' +
'Add "global" in the beginning to change your global profile\'s bio.'
return messagesText.helpText.emotes
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/HelpHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class HelpHandler extends DefaultHandler {
// public messageType = MessageType

public prefix = ['help', 'commands']
public helpText = () => 'rubber ducky 🦆 Never lucky.'
public helpText = () => messagesText.helpText.help

public async onCommand (msg: PrivmsgMessage, words: string[]) {
const responseMessage = this.getNameAndIds(msg)
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/JoinChatHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JOINCHAT, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class JoinChannelHandler extends DefaultHandler {
Expand All @@ -24,7 +25,7 @@ export default class JoinChannelHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
messagesText.twitchUserNotFound,
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Handlers/LeaveChatHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageType, LEAVECHAT } from 'befriendlier-shared'
import { LEAVECHAT, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class LeaveChannelHandler extends DefaultHandler {
Expand All @@ -25,7 +26,7 @@ export default class LeaveChannelHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
messagesText.twitchUserNotFound,
)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Handlers/MatchHandler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { BASE, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class MatchHandler extends DefaultHandler {
public messageType = MessageType.MATCH

public prefix = ['match', 'yes']

public helpText = () => 'attempts to match with the profile.'
public helpText = () => messagesText.helpText.match

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

const foundUserRoll = this.twitch.getUserInstance(msg)

if (foundUserRoll === undefined) {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
messagesText.notInitializedARoll,
)
return
}

Expand Down
8 changes: 7 additions & 1 deletion src/Handlers/MoreHandler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { MessageType, ROLLMATCH } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class MoreHandler extends DefaultHandler {
// public messageType = MessageType

public prefix = ['more']

public helpText = () => 'returns more information about the rolled profile.'
public helpText = () => messagesText.helpText.more

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

const foundUserRoll = this.twitch.getUserInstance(msg)

if (foundUserRoll === undefined) {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
messagesText.notInitializedARoll,
)
return
}

Expand Down
8 changes: 7 additions & 1 deletion src/Handlers/NoHandler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class NoHandler extends DefaultHandler {
// public messageType = MessageType

public prefix = ['no', 'mismatch']

public helpText = () => 'will add the rolled profile to your mismatches.'
public helpText = () => messagesText.helpText.no

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

const foundUserRoll = this.twitch.getUserInstance(msg)

if (foundUserRoll === undefined) {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
messagesText.notInitializedARoll,
)
return
}

Expand Down
5 changes: 3 additions & 2 deletions src/Handlers/PingHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { BASE, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class PingHandler extends DefaultHandler {
public messageType = MessageType.PING

public prefix = ['ping']

public helpText = () => 'returns ping info about Twitch IRC & Website.'
public helpText = () => messagesText.helpText.ping

public async onCommand (msg: PrivmsgMessage) {
const responseMessage = this.getNameAndIds(msg)
Expand All @@ -25,7 +26,7 @@ export default class PingHandler extends DefaultHandler {
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.`,
`Ping from Bot to Website: ~${String(Date.now() - res.timestamp)} ms.`,
)
} else {
// TODO: Looks like this is a healthcheck!
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/RollMatchHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageType, ROLLMATCH, More } from 'befriendlier-shared'
import { MessageType, More, ROLLMATCH } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class RollMatchHandler extends DefaultHandler {
Expand All @@ -8,8 +9,7 @@ export default class RollMatchHandler extends DefaultHandler {
public prefix = ['swipe', 'roll']

public helpText = () => {
return 'initiates a match! Good luck, rubber ducky 🦆' +
'Append "global" to initiate a match with global profiles.'
return messagesText.helpText.rollMatch
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/TakeABreakHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BASE, MessageType } from 'befriendlier-shared'
import messagesText from 'src/messagesText'
import DefaultHandler from './DefaultHandler'

export default class TakeABreakHandler extends DefaultHandler {
Expand All @@ -12,8 +13,7 @@ export default class TakeABreakHandler extends DefaultHandler {
this.twitch.sendMessage(
channelTwitch,
userTwitch,
result !== undefined && result.value.length > 0
? result.value : 'take a break! You\'re currently on a cooldown period.',
result !== undefined && result.value.length > 0 ? result.value : messagesText.takeABreak,
)

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
Expand Down
5 changes: 3 additions & 2 deletions src/Handlers/UnmatchHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { UNMATCH, MessageType } from 'befriendlier-shared'
import { PrivmsgMessage } from 'dank-twitch-irc'
import DefaultHandler from './DefaultHandler'
import messagesText from 'src/messagesText'

export default class UnmatchHandler extends DefaultHandler {
public messageType = MessageType.UNMATCH

public prefix = ['unmatch']

public helpText = () => {
return 'unmatches with the provided user. Append "global" to unmatch with a user in your global profile.'
return messagesText.helpText.unmatch
}

public async onCommand (msg: PrivmsgMessage, words: string[]) {
Expand All @@ -27,7 +28,7 @@ export default class UnmatchHandler extends DefaultHandler {
this.twitch.sendMessage(
responseMessage.channelTwitch,
responseMessage.userTwitch,
'could not find that user on Twitch.',
messagesText.twitchUserNotFound,
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/UnregisteredHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BASE, MessageType } from 'befriendlier-shared'
import DefaultHandler from './DefaultHandler'
import messagesText from 'src/messagesText'

export default class UnregisteredHandler extends DefaultHandler {
public messageType = MessageType.UNREGISTERED
Expand All @@ -9,7 +10,7 @@ export default class UnregisteredHandler extends DefaultHandler {
// public async onCommand (msg: PrivmsgMessage) {}

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

this.twitch.removeUserInstance({ channelTwitch, userTwitch })
}
Expand Down
5 changes: 3 additions & 2 deletions src/Twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class Client {
private readonly ws: Ws
private readonly logger: Logger

private readonly name: string
public readonly name: string
private readonly id: string

public readonly commandPrefix: string
Expand Down Expand Up @@ -255,7 +255,7 @@ export default class Client {
}

// TODO: REFACTOR THIS LATER.
if (msg.messageText === '!befriendlier') {
if (msg.messageText === `!${this.name}`) {
const msgBot = { ...msg }
msgBot.messageText = '@@bot'

Expand Down Expand Up @@ -360,6 +360,7 @@ export default class Client {
return
}
}

for (const [, cachedMsg] of this.msgs) {
const removeMsgBool = (msg instanceof ClearchatMessage)
? cachedMsg.msg.channelName === msg.channelName
Expand Down
Loading

0 comments on commit 95ab939

Please sign in to comment.