fix bot activity & config update

This commit is contained in:
Hirzi
2022-11-29 14:44:15 +00:00
parent 750118e287
commit f7ace80089
4 changed files with 60 additions and 35 deletions
+16 -16
View File
@@ -3,10 +3,10 @@
# Bot Configuration
token: 'Put bot token here'
bot_status:
enable: false
presence:
text: 'Hosting Panel'
type: 'WATCHING' # can be 'WATCHING', 'PLAYING', 'LISTENING', or 'COMPETING'. for 'STREAMING' is not working for now
type: 'watching' # can be 'watching', 'playing', 'listening', or 'competing'. for 'streaming' is not working for now
status: 'online' # can be 'online', 'idle', 'dnd', or 'invisible'
# Discord Channel and Refresh Time Configuration
channel: 'Put channel id here'
@@ -18,10 +18,10 @@ panel:
key: 'Put panel apikey here'
# Message Configuration
# set to false if you want to disable option
# leave '' if you want to disable option
message:
content: false
attachment: false # If you enable attachment on message it upload the attachment first before sending or editing message and it will delay the stats
content: ''
attachment: '' # If you enable attachment on message it upload the attachment first before sending or editing message and it will delay the stats
embed:
title: 'PteroStats'
@@ -29,12 +29,11 @@ embed:
description: 'Next update {{time}}' # You can use {{time}} to make "in X seconds" time format
footer: 'By Hirzi#8701'
timestamp: true
thumbnail: false
image: false
thumbnail: ''
image: ''
field:
enable: false
title: 'Custom Field'
description: 'Custom Field' # You can use {{time}} to make "in X seconds" time format
title: ''
description: '' # You can use {{time}} to make "in X seconds" time format
# Message Button Configuration
button:
@@ -56,12 +55,14 @@ button:
url: ''
# Status Message Configuration
# How to use custom emoji: htttps://github.com/HirziDevs/PteroStats#using-custom-emoji
status:
online: ':green_circle: Online'
offline: ':red_circle: Offline'
# Nodes Resource
nodes_resource:
# Nodes Settings
# How to get nodes id: htttps://github.com/HirziDevs/PteroStats#blacklist-nodes
nodes_settings:
blacklist: [] # You can add node id to remove the node from status embed (Example: "blacklist: [1]")
enable: false
servers: true
@@ -69,8 +70,7 @@ nodes_resource:
allocations: true
unit: 'gb' # You can use "gb", "mb", "tb", or "percent"
# Panel Users and Servers
panel_resource:
enable: true
# Panel Users and Servers Settings
panel_settings:
servers: true
users: true
+30 -5
View File
@@ -1,3 +1,4 @@
const { ActivityType } = require('discord.js')
const chalk = require('chalk')
const checkStatus = require('../handlers/checkStatus')
@@ -10,12 +11,36 @@ module.exports = {
if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! This bot is not on any discord servers'))
if (client.config.refresh < 10) console.log(chalk.cyan('[PteroStats] ') + chalk.red('Refresh lower than 10 seconds is not recommended!'))
if (client.config.bot_status.enable && client.config.bot_status.text.length > 0) {
if (!['PLAYING', 'WATCHING', 'LISTENING', 'COMPETING'].includes(client.config.bot_status.type.toUpperCase() || client.config.bot_status.type.length < 1)) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! Invalid Status Type!, Can be "WATCHING", "PLAYING", "LISTENING", or "COMPETING"'))
} else {
client.user.setActivity(client.config.bot_status.text, { type: client.config.bot_status.type.toUpperCase() })
if (client.config.bot_status || client.config.nodes_resource || client.config.panel_resource) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('You used `bot_status`, `panel_resource` and `nodes_resource` instead of `presence`, `panel_settings` and `nodes_settings` in the config, please update your config file at ') + chalk.green('https://github.com/HirziDevs/PteroStats/blob/main/config.yml ') + chalk.red('before it can no longer be supported'))
client.config.presence = client.config.bot_status
client.config.nodes_settings = client.config.nodes_resource
client.config.panel_settings = client.config.panel_resource
}
if (client.config.presence.text && client.config.presence.type) {
switch (client.config.presence.type.toLowerCase()) {
case 'playing':
client.config.presence.type = ActivityType.Playing
break;
case 'listening':
client.config.presence.type = ActivityType.Listening
break;
case 'competing':
client.config.presence.type = ActivityType.Competing
break;
default:
client.config.presence.type = ActivityType.Watching
}
client.user.setActivity(client.config.presence.text, { type: client.config.presence.type })
}
if (client.config.presence.status) {
if (!['idle', 'online', 'dnd', 'invisible'].includes(client.config.presence.status.toLowerCase())) client.config.presence.status = 'online'
client.user.setStatus(client.config.presence.status);
}
checkStatus({ client: client })
+13 -13
View File
@@ -14,8 +14,8 @@ module.exports = async function postStatus({ client, panel, nodes }) {
let blacklist = 0
let content = null
if (!client.config.nodes_resource.blacklist) client.config.nodes_resource.blacklist = []
if (!Array.isArray(client.config.nodes_resource.blacklist) && Number.isInteger(client.config.nodes_resource.blacklist)) client.config.nodes_resource.blacklist = [client.config.nodes_resource.blacklist]
if (!client.config.nodes_settings.blacklist) client.config.nodes_settings.blacklist = []
if (!Array.isArray(client.config.nodes_settings.blacklist) && Number.isInteger(client.config.nodes_settings.blacklist)) client.config.nodes_settings.blacklist = [client.config.nodes_settings.blacklist]
if (client.guilds.cache.size < 1) return console.log(chalk.cyan('[PteroStats] ') + chalk.red('Error! This bot is not on any discord servers'))
if (messages && messages.embeds.length < 1) {
messages.delete()
@@ -37,10 +37,10 @@ module.exports = async function postStatus({ client, panel, nodes }) {
const stats = new Promise((resolve, reject) => {
if (nodes.length !== 0) {
nodes.forEach((data, i) => {
if (!client.config.nodes_resource.blacklist.includes(data.id)) {
if (!client.config.nodes_settings.blacklist.includes(data.id)) {
const title = data.name + ': ' + String(data.status).replace('true', client.config.status.online).replace('false', client.config.status.offline)
let description = '```'
switch (client.config.nodes_resource.unit.toLowerCase()) {
switch (client.config.nodes_settings.unit.toLowerCase()) {
case 'tb':
description = description +
'\nMemory : ' + Math.floor(data.memory_min / (1024 * 1000)).toLocaleString() + ' TB / ' + Math.floor(data.memory_max / (1024 * 1000)).toLocaleString() + ' TB' +
@@ -62,20 +62,20 @@ module.exports = async function postStatus({ client, panel, nodes }) {
'\nDisk : ' + data.disk_min.toLocaleString() + ' MB / ' + data.disk_max.toLocaleString() + ' MB'
}
if (client.config.nodes_resource.servers) description = description + '\nServers : ' + data.total_servers.toLocaleString()
if (client.config.nodes_resource.location) description = description + '\nLocation : ' + data.location
if (client.config.nodes_resource.allocations) description = description + '\nAllocations : ' + data.allocations.toLocaleString()
if (client.config.nodes_settings.servers) description = description + '\nServers : ' + data.total_servers.toLocaleString()
if (client.config.nodes_settings.location) description = description + '\nLocation : ' + data.location
if (client.config.nodes_settings.allocations) description = description + '\nAllocations : ' + data.allocations.toLocaleString()
description = description + '\n```'
if (client.config.nodes_resource.enable) {
if (client.config.nodes_settings.enable) {
text = text + '\n**' + title.replace(':', ':**') + '\n' + description
} else {
text = text + '\n**' + title.replace(':', ':**')
}
} else {
blacklist = blacklist + 1
if (nodes.length - client.config.nodes_resource.blacklist.length < 1) text = '\nThere is no nodes to display'
if (nodes.length - client.config.nodes_settings.blacklist.length < 1) text = '\nThere is no nodes to display'
}
if (i + 1 === nodes.length) resolve()
@@ -100,16 +100,16 @@ module.exports = async function postStatus({ client, panel, nodes }) {
embed.setDescription(desc.replaceAll('{{time}}', format) + '\n**Nodes Stats [' + Math.floor(nodes.length - blacklist) + ']**' + text)
const EmbedFields = []
if (client.config.panel_resource.enable) {
if (client.config.panel_settings.users || client.config.panel_settings.servers) {
let stats = '**Status:** ' + String(panel.status).replace('true', client.config.status.online).replace('false', client.config.status.offline) + '\n\n'
if (client.config.panel_resource.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n'
if (client.config.panel_resource.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`')
if (client.config.panel_settings.users) stats = stats + 'Users: ' + String(panel.total_users).replace('-1', '`Unknown`') + '\n'
if (client.config.panel_settings.servers) stats = stats + 'Servers: ' + String(panel.total_servers).replace('-1', '`Unknown`')
EmbedFields.push({ name: 'Panel Stats', value: stats })
}
if (client.config.embed.field.enable) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) })
if (client.config.embed.field.title && client.config.embed.field.description) EmbedFields.push({ name: client.config.embed.field.title, value: client.config.embed.field.description.replaceAll('{{time}}', format) })
if (client.config.embed.timestamp) embed.setTimestamp()
if (EmbedFields.length > 0) embed.addFields(EmbedFields)
+1 -1
View File
@@ -33,7 +33,7 @@ const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.config = yaml.load(fs.readFileSync('./config.yml', 'utf8'));
if (client.config.panel.adminkey || client.config.resource || client.config.message.image) {
console.log(chalk.cyan('[PteroStats] ') + chalk.red('You are using old config file, please update your config file at https://github.com/HirziDevs/PteroStats/blob/main/config.yml !'))
console.log(chalk.cyan('[PteroStats] ') + chalk.red('You are using old config file, please update your config file at ') + chalk.green('https://github.com/HirziDevs/PteroStats/blob/main/config.yml '))
process.exit()
}
if (client.config.token.startsWith('Put') || !client.config.token.length) {