mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-18 00:31:00 -05:00
Compare commits
No commits in common. "65baaef5691b03c7bd42da63a05943e7041ceb92" and "5c0f2385314a89a6df31ca222522a0e300394407" have entirely different histories.
65baaef569
...
5c0f238531
@ -14,18 +14,18 @@ export default class HookMgr {
|
|||||||
this.webhookId = webhookId;
|
this.webhookId = webhookId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected channelFetch = async(channel:ChannelList)=>await this.client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel;
|
protected channelFetch = async(client:TClient, channel:ChannelList)=>await client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel;
|
||||||
protected async fetch(channel:ChannelList, webhookId:Discord.Snowflake) {
|
protected async fetch(client:TClient, channel:ChannelList, webhookId:Discord.Snowflake) {
|
||||||
const hookInstance = await (await this.channelFetch(channel)).fetchWebhooks().then(x=>x.find(y=>y.id===webhookId));
|
const hookInstance = await (await this.channelFetch(client, channel)).fetchWebhooks().then(x=>x.find(y=>y.id===webhookId));
|
||||||
if (!hookInstance) throw new Error('[HookManager] Webhook not found.');
|
if (!hookInstance) throw new Error('[HookManager] Webhook not found.');
|
||||||
return hookInstance;
|
return hookInstance;
|
||||||
}
|
}
|
||||||
async send(message:string|Discord.MessagePayload|Discord.WebhookMessageCreateOptions) {
|
async send(message:string|Discord.MessagePayload|Discord.WebhookMessageCreateOptions) {
|
||||||
const hook = await this.fetch(this.channel, this.webhookId);
|
const hook = await this.fetch(this.client, this.channel, this.webhookId);
|
||||||
return hook.send(message).catch(err=>(this.client.channels.resolve(config.dcServer.channels.errors) as Discord.TextChannel).send(`Failed to send a webhook message in #${this.channel}:\n\`\`\`\n${err.message}\n\`\`\``));
|
return hook.send(message).catch(err=>(this.client.channels.resolve(config.dcServer.channels.errors) as Discord.TextChannel).send(`Failed to send a webhook message in #${this.channel}:\n\`\`\`\n${err.message}\n\`\`\``));
|
||||||
}
|
}
|
||||||
async edit(messageId:Discord.Snowflake, message:string|Discord.MessagePayload|Discord.WebhookMessageEditOptions) {
|
async edit(messageId:Discord.Snowflake, message:string|Discord.MessagePayload|Discord.WebhookMessageEditOptions) {
|
||||||
const hook = await this.fetch(this.channel, this.webhookId);
|
const hook = await this.fetch(this.client, this.channel, this.webhookId);
|
||||||
return hook.editMessage(messageId, message).catch(err=>(this.client.channels.resolve(config.dcServer.channels.errors) as Discord.TextChannel).send(`Failed to edit a webhook message in #${this.channel}:\n\`\`\`\n${err.message}\n\`\`\``));
|
return hook.editMessage(messageId, message).catch(err=>(this.client.channels.resolve(config.dcServer.channels.errors) as Discord.TextChannel).send(`Failed to edit a webhook message in #${this.channel}:\n\`\`\`\n${err.message}\n\`\`\``));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
src/helpers/FormatPlayer.ts
Normal file
26
src/helpers/FormatPlayer.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import {FSPlayer} from '../interfaces';
|
||||||
|
export default class FormatPlayer {
|
||||||
|
static convertUptime(playTime:number) {
|
||||||
|
let Minutes:number;
|
||||||
|
let Hours:number;
|
||||||
|
let Days:number;
|
||||||
|
|
||||||
|
playTime = Math.floor(playTime);
|
||||||
|
if (playTime >= 60) {
|
||||||
|
Hours = Math.floor(playTime/60);
|
||||||
|
Minutes = playTime-Hours*60;
|
||||||
|
} else Minutes = playTime
|
||||||
|
|
||||||
|
if (Hours >= 24) {
|
||||||
|
Days = Math.floor(Hours/24);
|
||||||
|
Hours = Hours-Days*24;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Days > 0 ? Days+' d ':'')+(Hours > 0 ? Hours+' h ':'')+(Minutes > 0 ? Minutes+' m':'')
|
||||||
|
}
|
||||||
|
static decoratePlayerIcons(player:FSPlayer) {
|
||||||
|
let decorator = player.isAdmin ? ':detective:' : '';
|
||||||
|
decorator += player.name.includes('Toast') ? '<:toast:1132681026662056079>' : '';
|
||||||
|
return decorator
|
||||||
|
}
|
||||||
|
}
|
@ -110,17 +110,7 @@ export class PunishmentsSvc {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
async createModlog(punishment:Punishment) {
|
async createModlog(punishment:Punishment) {
|
||||||
let channel:Discord.TextChannelResolvable;
|
const channel = ['kick', 'ban'].includes(punishment.type) ? this.client.config.dcServer.channels.bankick_log : this.client.config.dcServer.channels.logs;
|
||||||
switch (punishment.type) {
|
|
||||||
case 'kick':
|
|
||||||
case 'ban':
|
|
||||||
channel = this.client.config.dcServer.channels.bankick_log;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
channel = this.client.config.dcServer.channels.logs;
|
|
||||||
console.log('[Punishment] BKL channel doesn\'t seem to exist anymore, falling back to #bot-log.')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const embed = new this.client.embed()
|
const embed = new this.client.embed()
|
||||||
.setColor(this.client.config.embedColor)
|
.setColor(this.client.config.embedColor)
|
||||||
.setTitle(`${punishment.type[0].toUpperCase() + punishment.type.slice(1)} | Case #${punishment.case_id}`)
|
.setTitle(`${punishment.type[0].toUpperCase() + punishment.type.slice(1)} | Case #${punishment.case_id}`)
|
||||||
|
@ -2,6 +2,7 @@ import Undici from 'undici';
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import ConfigHelper from '../helpers/ConfigHelper.js';
|
import ConfigHelper from '../helpers/ConfigHelper.js';
|
||||||
|
import FormatPlayer from '../helpers/FormatPlayer.js';
|
||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
import HookMgr from '../components/HookManager.js';
|
import HookMgr from '../components/HookManager.js';
|
||||||
import {IServer} from '../models/MPServer.js';
|
import {IServer} from '../models/MPServer.js';
|
||||||
@ -120,6 +121,10 @@ async function multifarmWebhook(client:TClient, server:IServer, webhookId:string
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function storePlayerCount(client:TClient, server:IServer, playerCount:number) {
|
||||||
|
return await client.MPServer.incrementPlayerCount(server.serverName, playerCount);
|
||||||
|
}
|
||||||
|
|
||||||
export async function requestServerData(client:TClient, server:IServer):Promise<{dss:FSData, csg:FSCareerSavegame}|undefined>{
|
export async function requestServerData(client:TClient, server:IServer):Promise<{dss:FSData, csg:FSCareerSavegame}|undefined>{
|
||||||
async function retryReqs(url:string) {
|
async function retryReqs(url:string) {
|
||||||
// Attempt to reduce the failure rate of the requests before giving up and retrying in next refresh.
|
// Attempt to reduce the failure rate of the requests before giving up and retrying in next refresh.
|
||||||
@ -151,31 +156,11 @@ export async function requestServerData(client:TClient, server:IServer):Promise<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mpModuleDisabled =(client:TClient)=>new client.embed().setColor(client.config.embedColorInvis).setTitle('MPModule is currently disabled.');
|
export function mpModuleDisabled(client:TClient) {
|
||||||
export const playtimeStat =(player:FSPlayer)=>`**${player.name}${decoratePlayerIcons(player)}**\n${player.uptime < 1 ? 'Just joined' : `Playing for ${convertPlayerUptime(player.uptime)}`}`;
|
return new client.embed().setColor(client.config.embedColorInvis).setTitle('MPModule is currently disabled.');
|
||||||
const storePlayerCount = async(client:TClient, server:IServer, playerCount:number)=>await client.MPServer.incrementPlayerCount(server.serverName, playerCount);
|
|
||||||
|
|
||||||
function decoratePlayerIcons(player:FSPlayer) {
|
|
||||||
let decorator = player.isAdmin ? ':detective:' : '';
|
|
||||||
decorator += player.name.includes('Toast') ? '<:toast:1132681026662056079>' : '';
|
|
||||||
return decorator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertPlayerUptime(playTime:number) {
|
export function playtimeStat(player:FSPlayer) {
|
||||||
let Minutes:number;
|
let uptimeTxt = player.uptime < 1 ? 'Just joined' : `Playing for ${FormatPlayer.convertUptime(player.uptime)}`;
|
||||||
let Hours:number;
|
return `**${player.name}${FormatPlayer.decoratePlayerIcons(player)}**\n${uptimeTxt}`
|
||||||
let Days:number;
|
|
||||||
|
|
||||||
playTime = Math.floor(playTime);
|
|
||||||
if (playTime >= 60) {
|
|
||||||
Hours = Math.floor(playTime/60);
|
|
||||||
Minutes = playTime-Hours*60;
|
|
||||||
} else Minutes = playTime
|
|
||||||
|
|
||||||
if (Hours >= 24) {
|
|
||||||
Days = Math.floor(Hours/24);
|
|
||||||
Hours = Hours-Days*24;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Days > 0 ? Days+' d ':'')+(Hours > 0 ? Hours+' h ':'')+(Minutes > 0 ? Minutes+' m':'')
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user