Skip to content

Commit

Permalink
feat: allow configuration of the emoji and separator
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCuthbert committed Nov 10, 2019
1 parent 89c9766 commit 5b846c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Variable | Default | Description
`LAST_FM_KEY` | | Access to Last.fm data
`LAST_FM_USERNAME` | | Which user to get track info for
`SLACK_TOKEN` | | Personal "legacy" token for updating your Slack status
`SLACK_EMOJI` | `:headphones:` | Specify which emoji to use in the status
`SLACK_SEPARATOR` | `` | Specify which character to use as a separator between the track name and artist
`TZ` | `UTC` | Set the timezone
`ACTIVE_HOURS_START` | `9` | The hour of the day to start updating your Slack status
`ACTIVE_HOURS_END` | `17` | The hour of the day to stop updating your Slack status
Expand Down
6 changes: 5 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const {
LAST_FM_SECRET = '',
LAST_FM_USERNAME = '',
SLACK_TOKEN = '',
SLACK_EMOJI = ':headphones:',
SLACK_SEPARATOR = '•',
TZ = 'Australia/Melbourne',
ACTIVE_HOURS_START = '9',
ACTIVE_HOURS_END = '17',
Expand All @@ -19,7 +21,9 @@ export const lastFM = {

export const slack = {
apiUrl: 'https://slack.com/api',
token: SLACK_TOKEN
token: SLACK_TOKEN,
emoji: SLACK_EMOJI,
separator: SLACK_SEPARATOR
}

export const activeHours = {
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function setSlackStatus (status: string) {
const body = {
profile: {
status_text: status,
status_emoji: status !== '' ? ':headphones:' : '',
status_emoji: status !== '' ? config.slack.emoji : '',
status_expiration: 0
}
}
Expand Down Expand Up @@ -159,7 +159,9 @@ async function main () {

// Update!
let status = nowPlaying.name
status += ' • '
status += ' '
status += config.slack.separator
status += ' '
status += nowPlaying.artist['#text']

console.log(`${LOG_SLK} Setting status to "${status}"`)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function getNowPlaying (tracks: LastFM.Track[]) {
/**
* Returns true if the profile should be updated.
*
* It assumes that if a status is using the `:headphones:` emoji and contains a
* It assumes that if a status is using the configured emoji and contains a
* middle dot character (`•`) that the app has previously been used to update
* the status and should continue to.
*
Expand All @@ -93,6 +93,6 @@ export function getNowPlaying (tracks: LastFM.Track[]) {
*/
export function shouldSetStatus (profile: Slack.Profile) {
if (profile.status_emoji === '' && profile.status_text === '') return true
if (profile.status_emoji === ':headphones:' && profile.status_text.includes(' • ')) return true
if (profile.status_emoji === config.slack.emoji && profile.status_text.includes(' • ')) return true
return false
}

0 comments on commit 5b846c1

Please sign in to comment.