Skip to content

Commit

Permalink
change Discord message
Browse files Browse the repository at this point in the history
  • Loading branch information
j-catania committed Feb 11, 2024
1 parent 6d63935 commit d8712f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/services/checker/HttpChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ const check = async (service, status) => {
if (!resp.ok) {
throw new Error(`${resp.status} ${resp.statusText}`)
}
if (myStatus.status === 'down') {
NotifierService.notify(service, 'up')
if (myStatus.status === 'offline') {
NotifierService.notify(service, 'online')
myStatus.message = undefined
}
myStatus.status = 'up'
myStatus.status = 'online'
} catch (error) {
myStatus.message = error.message
if (status.status === 'up') {
NotifierService.notify(service, 'down', status.message)
if (status.status === 'online') {
NotifierService.notify(service, 'offline', status.message)
}
myStatus.status = 'down'
myStatus.status = 'offline'
} finally {
myStatus.date = new Date()
clearTimeout(timeout)
Expand Down
2 changes: 1 addition & 1 deletion src/services/notifier/NotifierService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('NotifierService', () => {

describe('notify', () => {
it('should call notify for each notifier', () => {
NotifierService.notify(services[0], 'UP')
NotifierService.notify(services[0], 'online')
expect(mockNotify).toHaveBeenCalledTimes(1)
})
})
Expand Down
8 changes: 4 additions & 4 deletions src/services/notifier/providers/DiscordNotifierProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const { error } = console
const notify = (name, status, notifier, desc) => {
const hook = new Webhook(notifier.webhook)
const message = new MessageBuilder()
.setTitle(`${name} status changed`)
.setTitle(`${name} is ${status}`)
.addField('Service', name, true)
.addField('Status', status)
.setColor(status === 'down' ? '#b71717' : '#17b75c')
.setThumbnail('https://cdn.discordapp.com/embed/avatars/0.png')
.setColor(status === 'offline' ? '#b71717' : '#17b75c')
.setThumbnail('https://cdn-icons-png.flaticon.com/512/3004/3004458.png')
.setDescription(desc ?? '')

hook.setUsername('eMusk')
Expand All @@ -35,7 +35,7 @@ const hello = (name, notifier, version) => {
const message = new MessageBuilder()
.setTitle(`'${name}' is protected by eMusk v${version}`)
.setColor('#5d0bda')
.setDescription('Hi, I\'m eMusk, I\'m here to notify you when your service is down')
.setDescription('Hi, I\'m eMusk, I\'m here to notify you when your service is offline')

hook.setUsername('eMusk')
hook.send(message)
Expand Down
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ServiceStatus = {
message?: string;
}

type Status = 'down' | 'up' | 'unknown'
type Status = 'offline' | 'online' | 'unknown'

type ServiceNotifier = {
webhook?: string;
Expand Down

0 comments on commit d8712f1

Please sign in to comment.