1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-29 01:25:38 -05:00

i feel like i made it worse but atleast its good enough.

This commit is contained in:
AnxietyisReal 2022-11-22 09:37:23 +11:00
parent d202156ee6
commit a6e61cccfe
2 changed files with 16 additions and 7 deletions

View File

@ -6,6 +6,7 @@ async function MPdata(client:TClient, interaction:Discord.ChatInputCommandIntera
let FSserver; let FSserver;
MPDB.sync(); MPDB.sync();
const newServerId = interaction.guildId; const newServerId = interaction.guildId;
if (!await MPDB.findOne({where: {serverId: newServerId}})) return interaction.reply('This server isn\'t linked.')
const ServerURL = await MPDB.findOne({where: { serverId: newServerId }}); const ServerURL = await MPDB.findOne({where: { serverId: newServerId }});
if (!ServerURL) return interaction.reply(`No gameserver found, please contact <@&${client.config.mainServer.roles.mpmanager}> to add it.`) if (!ServerURL) return interaction.reply(`No gameserver found, please contact <@&${client.config.mainServer.roles.mpmanager}> to add it.`)
const DBURL = ServerURL.ip const DBURL = ServerURL.ip
@ -32,7 +33,7 @@ export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (interaction.channelId == '468835769092669461' && !client.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) { if (interaction.channelId == '468835769092669461' && !client.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) {
interaction.reply(`Please use <#739084625862852715> for \`/mp status/players\` commands to prevent clutter in this channel.`).then((msg)=>{ interaction.reply(`Please use <#739084625862852715> for \`/mp status/players\` commands to prevent clutter in this channel.`).then((msg)=>{
setTimeout(()=>{interaction.deleteReply()}, 5000) setTimeout(()=>{interaction.deleteReply()}, 6000)
}); });
return; return;
} }
@ -41,6 +42,7 @@ export default {
case 'status': case 'status':
const embed0 = new client.embed(); const embed0 = new client.embed();
const FSserver0 = await MPdata(client, interaction, embed0); const FSserver0 = await MPdata(client, interaction, embed0);
if (!FSserver0.data) return console.log('FSserver0 failed')
if (FSserver0.data.server.name.length > 1) { if (FSserver0.data.server.name.length > 1) {
embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields( embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields(
{name: 'Server name', value: `${FSserver0?.data.server.name.length == 0 ? '\u200b' : `\`${FSserver0?.data.server.name}\``}`, inline: true}, {name: 'Server name', value: `${FSserver0?.data.server.name.length == 0 ? '\u200b' : `\`${FSserver0?.data.server.name}\``}`, inline: true},
@ -49,6 +51,14 @@ export default {
{name: 'Version', value: `${FSserver0?.data.server.version.length == 0 ? '\u200b' : FSserver0.data.server.version}`, inline: true}, {name: 'Version', value: `${FSserver0?.data.server.version.length == 0 ? '\u200b' : FSserver0.data.server.version}`, inline: true},
{name: 'In-game Time', value: `${('0' + Math.floor((FSserver0.data.server.dayTime/3600/1000))).slice(-2)}:${('0' + Math.floor((FSserver0.data.server.dayTime/60/1000)%60)).slice(-2)}`, inline: true} {name: 'In-game Time', value: `${('0' + Math.floor((FSserver0.data.server.dayTime/3600/1000))).slice(-2)}:${('0' + Math.floor((FSserver0.data.server.dayTime/60/1000)%60)).slice(-2)}`, inline: true}
) )
} else if (FSserver0.data.server.name.length == 0) {
embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields(
{name: 'Server name', value: `\`Official Daggerwin Game Server\``, inline: true},
{name: 'Players', value: '0 out of 0', inline: true},
{name: 'Current map', value: 'Null Island', inline: true},
{name: 'Version', value: '0.0.0.0', inline: true},
{name: 'In-game Time', value: '00:00', inline: true}
)
} }
interaction.reply({embeds: [embed0]}) interaction.reply({embeds: [embed0]})
break; break;
@ -62,9 +72,7 @@ export default {
}); });
const first_graph_top = 16; const first_graph_top = 16;
const second_graph_top = 16; const second_graph_top = 16;
const textSize = 40; const textSize = 40;
const canvas = require('canvas'); const canvas = require('canvas');
@ -121,7 +129,6 @@ export default {
// draw points // draw points
ctx.lineWidth = 5; ctx.lineWidth = 5;
function getYCoordinate(value: number) { function getYCoordinate(value: number) {
return ((1 - (value / second_graph_top)) * graphSize[1]) + graphOrigin[1]; return ((1 - (value / second_graph_top)) * graphSize[1]) + graphOrigin[1];
} }
@ -210,6 +217,7 @@ export default {
const Image = new client.attachmentBuilder(img.toBuffer(),{name: 'FSStats.png'}) const Image = new client.attachmentBuilder(img.toBuffer(),{name: 'FSStats.png'})
embed1.setImage('attachment://FSStats.png') embed1.setImage('attachment://FSStats.png')
const FSserver1 = await MPdata(client, interaction, embed1) const FSserver1 = await MPdata(client, interaction, embed1)
if (!FSserver1.data) return console.log('FSserver1 failed')
embed1.setTitle(FSserver1?.data.server.name.length == 0 ? 'Offline' : FSserver1?.data.server.name) embed1.setTitle(FSserver1?.data.server.name.length == 0 ? 'Offline' : FSserver1?.data.server.name)
.setDescription(`${FSserver1?.data.slots.used}/${FSserver1?.data.slots.capacity}`) .setDescription(`${FSserver1?.data.slots.used}/${FSserver1?.data.slots.capacity}`)
.setColor(FSserver1?.data.server.name.length == 0 ? client.config.embedColorRed : client.config.embedColor); .setColor(FSserver1?.data.server.name.length == 0 ? client.config.embedColorRed : client.config.embedColor);
@ -221,6 +229,7 @@ export default {
case 'info': case 'info':
const embed2 = new client.embed().setColor(client.config.embedColor) const embed2 = new client.embed().setColor(client.config.embedColor)
const FSserver2 = await MPdata(client, interaction, embed2) const FSserver2 = await MPdata(client, interaction, embed2)
if (!FSserver2.data) return console.log('FSserver2 failed')
const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}}) const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}})
embed2.setDescription([ embed2.setDescription([
`**Server name**: \`Official Daggerwin Game Server\``, `**Server name**: \`Official Daggerwin Game Server\``,

View File

@ -141,7 +141,7 @@ setInterval(async()=>{
// Event loop for punishments and daily msgs // Event loop for punishments and daily msgs
setInterval(async()=>{ setInterval(async()=>{
const now = Date.now() const now = Date.now();
const lrsStart = client.config.LRSstart; const lrsStart = client.config.LRSstart;
client.punishments._content.filter((x:Punishment)=>x.endTime<= now && !x.expired).forEach(async (punishment:Punishment)=>{ client.punishments._content.filter((x:Punishment)=>x.endTime<= now && !x.expired).forEach(async (punishment:Punishment)=>{
@ -152,7 +152,7 @@ setInterval(async()=>{
const formattedDate = Math.floor((now - lrsStart)/1000/60/60/24); const formattedDate = Math.floor((now - lrsStart)/1000/60/60/24);
const dailyMsgs = require('./database/dailyMsgs.json'); const dailyMsgs = require('./database/dailyMsgs.json');
if (!dailyMsgs.some(x=>x[0] === formattedDate)){ if (!dailyMsgs.some((x:Array<number>)=>x[0] === formattedDate)){
let total = Object.values<UserLevels>(client.userLevels._content).reduce((a,b)=>a + b.messages, 0); // sum of all users let total = Object.values<UserLevels>(client.userLevels._content).reduce((a,b)=>a + b.messages, 0); // sum of all users
const yesterday = dailyMsgs.find((x:Array<number>)=>x[0] === formattedDate - 1); const yesterday = dailyMsgs.find((x:Array<number>)=>x[0] === formattedDate - 1);
if (total < yesterday){ // messages went down. if (total < yesterday){ // messages went down.