mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: more annotation for util functions
This commit is contained in:
1 parent
1ae9503477
commit
39e818283d
5 files changed
+64
-27
No files matched your search
@@ -62,3 +62,26 @@ export interface CannotSendMessageInChannelParams {
|
|||||||
interaction: ChatInputCommandInteraction;
|
interaction: ChatInputCommandInteraction;
|
||||||
executionId: string;
|
executionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetUptimeFormattedParams {
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StartLoadTestParams {
|
||||||
|
client: ExtendedClient;
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PostBotStatsParams {
|
||||||
|
client: ExtendedClient;
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PostBotStatsSite {
|
||||||
|
enabled: boolean;
|
||||||
|
hostname: string;
|
||||||
|
path: string;
|
||||||
|
method: string;
|
||||||
|
body: object;
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ const cookies = require(path.resolve('./cookies.json'));
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const cookieString = cookies
|
const cookieString = cookies
|
||||||
.map(({ name, value }) => {
|
.map(({ name, value }: { name: string; value: string }) => {
|
||||||
return `${name}=${value}`;
|
return `${name}=${value}`;
|
||||||
})
|
})
|
||||||
.join('; ');
|
.join('; ');
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
import https from 'node:https';
|
import https from 'node:https';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
|
import { PostBotStatsParams, PostBotStatsSite } from '../../types/utilTypes';
|
||||||
|
import { Collection, Guild } from 'discord.js';
|
||||||
|
|
||||||
export const postBotStats = async ({ client, executionId }) => {
|
export const postBotStats = async ({ client, executionId }: PostBotStatsParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'postBotStats.js',
|
source: 'postBotStats.js',
|
||||||
module: 'utilOther',
|
module: 'utilOther',
|
||||||
name: 'postBotStats',
|
name: 'postBotStats',
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: client.shard.ids[0]
|
shardId: client.shard?.ids[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (client.shard.ids[0] !== 0) {
|
if (client.shard?.ids[0] !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,10 +26,11 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
await client.shard
|
await client.shard
|
||||||
.fetchClientValues('guilds.cache')
|
.fetchClientValues('guilds.cache')
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
results.map((guildCache) => {
|
const guildCaches = results as Collection<string, Guild>[];
|
||||||
|
guildCaches.map((guildCache) => {
|
||||||
if (guildCache) {
|
if (guildCache) {
|
||||||
guildCount += guildCache.length;
|
guildCount += guildCache.size;
|
||||||
memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0);
|
memberCount += guildCache.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -38,7 +41,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
const sites = [
|
const sites: PostBotStatsSite[] = [
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
hostname: 'top.gg',
|
hostname: 'top.gg',
|
||||||
@@ -49,7 +52,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
shard_count: shardCount,
|
shard_count: shardCount,
|
||||||
server_count: guildCount
|
server_count: guildCount
|
||||||
},
|
},
|
||||||
token: process.env.BOTLIST_TOP_GG_API_TOKEN
|
token: process.env.BOTLIST_TOP_GG_API_TOKEN ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -61,7 +64,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
users: memberCount,
|
users: memberCount,
|
||||||
guilds: guildCount
|
guilds: guildCount
|
||||||
},
|
},
|
||||||
token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN
|
token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -71,7 +74,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
body: {
|
body: {
|
||||||
server_count: guildCount
|
server_count: guildCount
|
||||||
},
|
},
|
||||||
token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN
|
token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -83,7 +86,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
shardCount: shardCount,
|
shardCount: shardCount,
|
||||||
guildCount: guildCount
|
guildCount: guildCount
|
||||||
},
|
},
|
||||||
token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN
|
token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -94,7 +97,7 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
shard_count: shardCount,
|
shard_count: shardCount,
|
||||||
server_count: guildCount
|
server_count: guildCount
|
||||||
},
|
},
|
||||||
token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN
|
token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -120,10 +123,10 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
|
|
||||||
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
||||||
|
|
||||||
const statusCodes = [];
|
const statusCodes: number[] = [];
|
||||||
|
|
||||||
sites.map((site) => {
|
sites.map((site) => {
|
||||||
if (site.disabled) {
|
if (!site.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,11 +143,17 @@ export const postBotStats = async ({ client, executionId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const request = https.request(options, (res) => {
|
const request = https.request(options, (res) => {
|
||||||
res.statusCode === 200
|
if (typeof res.statusCode === 'number') {
|
||||||
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
res.statusCode === 200
|
||||||
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
||||||
|
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
||||||
|
|
||||||
statusCodes.push(res.statusCode);
|
statusCodes.push(res.statusCode);
|
||||||
|
} else {
|
||||||
|
logger.error(
|
||||||
|
`Request to ${site.hostname}: statusCode is undefined or not a number (${res.statusCode}).`
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request.write(JSON.stringify(site.body));
|
request.write(JSON.stringify(site.body));
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
const loadTestOptions = config.get('loadTestOptions');
|
import { LoadTestOptions } from '../../types/configTypes';
|
||||||
|
import { Client } from 'discord.js';
|
||||||
|
import { StartLoadTestParams } from '../../types/utilTypes';
|
||||||
|
const loadTestOptions: LoadTestOptions = config.get('loadTestOptions');
|
||||||
|
|
||||||
export const startLoadTest = async ({ client, executionId }) => {
|
export const startLoadTest = async ({ client, executionId }: StartLoadTestParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'startLoadTest.js',
|
source: 'startLoadTest.js',
|
||||||
module: 'utilOther',
|
module: 'utilOther',
|
||||||
name: 'startLoadTest',
|
name: 'startLoadTest',
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: client.shard.ids[0]
|
shardId: client.shard?.ids[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!loadTestOptions.enabled) {
|
if (!loadTestOptions.enabled) {
|
||||||
@@ -22,11 +25,12 @@ export const startLoadTest = async ({ client, executionId }) => {
|
|||||||
logger.info(`Starting load test in ${channelIds.length} specified channels.`);
|
logger.info(`Starting load test in ${channelIds.length} specified channels.`);
|
||||||
|
|
||||||
channelIds.forEach((each) => {
|
channelIds.forEach((each) => {
|
||||||
client.shard.broadcastEval(
|
client.shard?.broadcastEval(
|
||||||
async (shardClient, { channelId, track }) => {
|
async (shardClient: Client, { channelId, track }: { channelId: string; track: string }) => {
|
||||||
const channel = shardClient.channels.cache.get(channelId);
|
const channel = shardClient.channels.cache.get(channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
/* eslint-disable no-undef */
|
/* eslint-disable no-undef */
|
||||||
|
// @ts-ignore
|
||||||
await player.play(channel.id, track, {
|
await player.play(channel.id, track, {
|
||||||
nodeOptions: {
|
nodeOptions: {
|
||||||
leaveOnEmpty: false,
|
leaveOnEmpty: false,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
|
import { GetUptimeFormattedParams } from '../../types/utilTypes';
|
||||||
|
|
||||||
export const getUptimeFormatted = async ({ executionId }) => {
|
export const getUptimeFormatted = async ({ executionId }: GetUptimeFormattedParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'getUptimeFormatted.js',
|
source: 'getUptimeFormatted.js',
|
||||||
module: 'utilSystem',
|
module: 'utilSystem',
|
||||||
@@ -11,9 +12,9 @@ export const getUptimeFormatted = async ({ executionId }) => {
|
|||||||
try {
|
try {
|
||||||
let uptimeFormattedString = '';
|
let uptimeFormattedString = '';
|
||||||
|
|
||||||
const uptimeInSeconds = process.uptime();
|
const uptimeInSeconds = parseFloat(process.uptime().toFixed(0));
|
||||||
const uptimeDate = new Date(0);
|
const uptimeDate = new Date(0);
|
||||||
uptimeDate.setSeconds(uptimeInSeconds.toFixed(0));
|
uptimeDate.setSeconds(uptimeInSeconds);
|
||||||
uptimeFormattedString = `${
|
uptimeFormattedString = `${
|
||||||
uptimeDate.getUTCDate() - 1
|
uptimeDate.getUTCDate() - 1
|
||||||
}d ${uptimeDate.getUTCHours()}h ${uptimeDate.getUTCMinutes()}m ${uptimeDate.getUTCSeconds()}s`;
|
}d ${uptimeDate.getUTCHours()}h ${uptimeDate.getUTCMinutes()}m ${uptimeDate.getUTCSeconds()}s`;
|
||||||
|
|||||||
Reference in new issue
Block a user