Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Feature: Proper game rotation and selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceheliflyer committed Apr 8, 2018
1 parent 5b289b2 commit 661d08c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/config/gameConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# http://discord.js.org/#/docs/main/master/typedef/PresenceData
enabled: false
rotate: false # When false, selects first game.
rotateTime: 150000 # Rotate speed in miliseconds. (This still applies even if rotate is disabled.)

# WARNING: This uses eval to work, careful what you set each value at.
# If using STREAMING type, you must supply a proper Twitch link.
games:
- activityName: "${client.options.commandPrefix}help | ${client.guilds.size.toLocaleString()} ${pluralize('Server', client.guilds.size)} | ${client.users.size.toLocaleString()} ${pluralize('User', client.users.size)} ${client.shard ? ` | Shard ${client.shard.id}` : ''}"
status: 'online'

- activityName: '${client.options.commandPrefix}help'
activityType: 'LISTENING' # Listening to
status: 'idle'

- activityName: '${client.options.commandPrefix}stats to view stats.'
status: 'dnd'
60 changes: 39 additions & 21 deletions src/events/client/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@ const { oneLine } = require('common-tags')
module.exports = async (client) => {
await client.log('success', `Logged in as ${client.user.tag} (${client.user.id}).`, 'Discord', 'Login')

await setTimeout(() => {
client.user.setStatus(client.provider.get('global', 'clientStatus', 'online')).then(
client.user.setActivity(oneLine`
${client.options.commandPrefix}help |
${pluralize('Server', client.guilds.size.toLocaleString(), true)} |
${pluralize('User', client.users.size.toLocaleString(), true)}
${client.shard ? ` | Shard ${client.shard.id}` : ''}
`)
)
}, 1000)

await setInterval(() => {
client.user.setStatus(client.provider.get('global', 'clientStatus', 'online')).then(
client.user.setActivity(oneLine`
${client.options.commandPrefix}help |
${pluralize('Server', client.guilds.size.toLocaleString(), true)} |
${pluralize('User', client.users.size.toLocaleString(), true)}
${client.shard ? ` | Shard ${client.shard.id}` : ''}
`)
)
}, 600000)
if (client.config.gameConfig.enabled === true) {
var games = client.config.gameConfig.games
if (client.config.gameConfig.rotate === false) {
client.user.setPresence(await calcPresence(client, games[0]))
setInterval(async () => {
client.user.setPresence(await calcPresence(client, games[0]))
}, client.config.gameConfig.rotateTime)
} else {
client.user.setPresence(await calcPresence(client, games[Math.floor(Math.random() * games.length)]))
setInterval(async () => {
client.user.setPresence(await calcPresence(client, games[Math.floor(Math.random() * games.length)]))
}, client.config.gameConfig.rotateTime)
}
}

await client.log('info', oneLine`
${client.shard ? `Shard ${client.shard.id} ready!` : 'Client Ready!'}
Expand Down Expand Up @@ -84,3 +77,28 @@ module.exports = async (client) => {
}
})
}

/**
* Dynamic presence hander.
* @param {object} game The object of the presence data.
*/
var calcPresence = (client, game) => {
var presence = {}; presence.activity = {}
// Presence Status
if (game.status) {
presence.status = game.status
}
// Activity Name
if (game.activityName) {
presence.activity.name = eval('`' + game.activityName + '`') // eslint-disable-line no-eval
}
// Activity Type
if (game.activityType) {
presence.activity.type = game.activityType
}
// Activity URL
if (game.activityURL) {
presence.activity.url = eval('`' + game.activityURL + '`') // eslint-disable-line no-eval
}
return presence
}

0 comments on commit 661d08c

Please sign in to comment.