Skip to content

Commit

Permalink
adding version to hello message
Browse files Browse the repository at this point in the history
  • Loading branch information
j-catania committed Dec 30, 2023
1 parent 53166b5 commit 2de8e55
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ program
.option('-h, --no-hello', 'Don\'t say hello to notifiers')
.option('-V, --verbose', 'Active more logs')
.option('-p, --port <port>', 'HTTP port', '1337')
.action(eMusk.start)
.action(eMusk.start({ version }))

program.parse()

Expand Down
4 changes: 2 additions & 2 deletions src/services/eMusk.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ const serviceStatuses = []
*/
let services

const start = async (opts) => {
const start = ({ version }) => async (opts) => {
const config = await ConfigService.get(opts.configFile)

services = config.services

Express.init(+opts.port, serviceStatuses)

if (opts.hello) NotifierService.hello(services)
if (opts.hello) NotifierService.hello(services, version)

services.forEach((service) => {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/services/notifier/NotifierService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const notify = (service, status, desc) => {
/**
* Send message to all notifiers for saying hello
* @param {Service[]} s
* @param {string} version
*/
const hello = (s) => {
const hello = (s, version) => {
const services = s.filter((ss) => ss.notifiers?.length > 0)

services.forEach((service) => {
service.notifiers.forEach((notifier) => {
switch (notifier.type) {
case 'discord': {
DiscordNotifierProvider.hello(service.name, notifier)
DiscordNotifierProvider.hello(service.name, notifier, version)
break
}
default:
Expand Down
9 changes: 5 additions & 4 deletions src/services/notifier/providers/DiscordNotifierProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ const notify = (name, status, notifier, desc) => {
* Say hello to discord
* @param {string} name Service name
* @param {ServiceNotifier} notifier Service notifier information
* @param {string} version
*/
const hello = (name, notifier) => {
const hello = (name, notifier, version) => {
const hook = new Webhook(notifier.webhook)
const message = new MessageBuilder()
.setTitle(`'${name}' is protected by eMusk`)
.setTitle(`'${name}' is protected by eMusk v${version}`)
.setColor('#5d0bda')
.setDescription('Hello, 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 down')

hook.setUsername('eMusk')
hook.send(message)
Expand All @@ -52,7 +53,7 @@ const goodbye = (name, notifier) => {
const message = new MessageBuilder()
.setTitle(`'${name}' is no more protected by eMusk`)
.setColor('#b7071f')
.setDescription('Hello, eMusk is no more protecting your service')
.setDescription('Hi, eMusk is no more protecting your service')

hook.setUsername('eMusk')
return hook.send(message)
Expand Down

0 comments on commit 2de8e55

Please sign in to comment.