1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 12:21:00 -05:00

some mp improvements and other stuff

This commit is contained in:
AnxietyisReal 2022-11-19 21:17:04 +11:00
parent 14df6be5ed
commit 158783e514
5 changed files with 26 additions and 21 deletions

View File

@ -3,7 +3,6 @@ import { TClient } from 'src/client';
import MPDB from '../models/MPServer'; import MPDB from '../models/MPServer';
export default { export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (interaction.guildId !== client.config.mainServer.id) return interaction.reply({content: 'This command doesn\'t work in this server.', ephemeral: true});
if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager'); if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager');
MPDB.sync(); MPDB.sync();
@ -15,17 +14,12 @@ export default {
const Url = await MPDB.findOne({where: {serverId: newServerId}}) const Url = await MPDB.findOne({where: {serverId: newServerId}})
if (Url.ip && Url.code){return interaction.reply(`${Url.get('ip')}` + '/feed/dedicated-server-stats.json?code=' + `${Url.get('code')}`)} if (Url.ip && Url.code){return interaction.reply(`${Url.get('ip')}` + '/feed/dedicated-server-stats.json?code=' + `${Url.get('code')}`)}
} catch(err) { } catch(err) {
if (err.name == 'SequelizeDatabaseError'){
console.log('MPDB | File doesn\'t exist in database folder, generating one now.')
interaction.reply('`MPDB.dat` is being createdm run the command again.')
} else {
console.log(`MPDB | Error: ${err}`) console.log(`MPDB | Error: ${err}`)
interaction.reply('Database error:\nTry inserting an URL first.') interaction.reply('**Database error:**\nTry inserting an URL first.')
}
} }
} else { } else {
const verifyURL = address.match(/feed/) const verifyURL = address.match(/feed/)
if (!verifyURL) return interaction.reply('Invalid URL, try again.') if (!verifyURL) return interaction.reply('That URL is not a valid `dedicated-server-stats.xml`')
const convertURL = address const convertURL = address
const newURL = convertURL.replace('xml','json').split('/feed/dedicated-server-stats.json?code=') const newURL = convertURL.replace('xml','json').split('/feed/dedicated-server-stats.json?code=')
try { try {
@ -33,12 +27,14 @@ export default {
const Url = await MPDB.create({ const Url = await MPDB.create({
serverId: newServerId, serverId: newServerId,
ip: newURL[0], ip: newURL[0],
code: newURL[1] code: newURL[1],
timesUpdated: 0
}); });
return interaction.reply(`Successfully set the URL to ${Url.ip}`) return interaction.reply(`Successfully set the URL to ${Url.ip}`)
} catch(err) { } catch(err) {
if (err.name == 'SequelizeUniqueConstraintError'){ if (err.name == 'SequelizeUniqueConstraintError'){
const AffectedRows = await MPDB.update({ip: newURL[0], code: newURL[1]},{where:{serverId: newServerId}}); const AffectedRows = await MPDB.update({ip: newURL[0], code: newURL[1]},{where:{serverId: newServerId}});
await MPDB.increment('timesUpdated', {where: {serverId: newServerId}});
if (AffectedRows){return interaction.reply(`Successfully updated the URL to ${newURL[0]}`)} if (AffectedRows){return interaction.reply(`Successfully updated the URL to ${newURL[0]}`)}
} else { } else {
console.log(err) console.log(err)
@ -50,9 +46,8 @@ export default {
}, },
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('url') .setName('url')
.setDescription('Update the URL for FSMP functions') .setDescription('View the URL for this server\'s FSMP server or update the URL')
.addStringOption((opt)=>opt .addStringOption((opt)=>opt
.setName('address') .setName('address')
.setDescription('Insert a \'dedicated-server-stats\' url') .setDescription('Insert a \'dedicated-server-stats\' url'))
.setRequired(false))
} }

View File

@ -7,11 +7,12 @@ async function MPdata(client:TClient, interaction:Discord.ChatInputCommandIntera
MPDB.sync(); MPDB.sync();
const newServerId = interaction.guildId; const newServerId = interaction.guildId;
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.`)
const DBURL = ServerURL.ip const DBURL = ServerURL.ip
const DBCode = ServerURL.code const DBCode = ServerURL.code
const verifyURL = DBURL.match(/http/) const verifyURL = DBURL.match(/http/)
const completedURL = DBURL + '/feed/dedicated-server-stats.json?code=' + DBCode const completedURL = DBURL + '/feed/dedicated-server-stats.json?code=' + DBCode
if (!verifyURL) return interaction.reply(`No gameserver found, please contact <@&${client.config.mainServer.roles.mpmanager}> to update it.`) if (!verifyURL) return interaction.reply(`Invalid gameserver IP, please contact <@&${client.config.mainServer.roles.mpmanager}> to update it.`)
// Fetch dss // Fetch dss
try { try {
@ -209,7 +210,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)
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);
FSserver1?.data.slots.players.filter(x=>x.isUsed).forEach(player=>{ FSserver1?.data.slots.players.filter(x=>x.isUsed).forEach(player=>{
@ -222,7 +223,7 @@ export default {
const FSserver2 = await MPdata(client, interaction, embed2) const FSserver2 = await MPdata(client, interaction, embed2)
const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}}) const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}})
embed2.setDescription([ embed2.setDescription([
`**Server name**: ${FSserver2?.data.server.name.length == 0 ? 'Unknown Server' : `\`${FSserver2.data.server.name}\``}`, `**Server name**: \`Official Daggerwin Game Server\``,
'**Password:** `mf4700`', '**Password:** `mf4700`',
'**Crossplay server**', '**Crossplay server**',
`**Map:** ${FSserver2.data.server.mapName.length == 0 ? 'Null Island' : FSserver2.data.server.mapName}`, `**Map:** ${FSserver2.data.server.mapName.length == 0 ? 'Null Island' : FSserver2.data.server.mapName}`,

View File

@ -6,7 +6,7 @@ export default {
if (message.author.bot) return; if (message.author.bot) return;
if (message.channel.type === ChannelType.DM) return; if (message.channel.type === ChannelType.DM) return;
const msgarr = message.content.toLowerCase().split(' '); const msgarr = message.content.toLowerCase().split(' ');
let automodded: any; let automodded: boolean;
function onTimeout(){ function onTimeout(){
delete client.repeatedMessages[message.author.id] delete client.repeatedMessages[message.author.id]
@ -19,7 +19,7 @@ export default {
if (client.bannedWords._content.some((x)=>msgarr.includes(x)) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){ if (client.bannedWords._content.some((x)=>msgarr.includes(x)) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){
automodded = true; automodded = true;
message.delete().catch((err)=>{ message.delete().catch((err)=>{
console.log('bannedWords automod; msg got possibly deleted by another bot or moderator.') console.log('bannedWords automod; msg got possibly deleted by another bot.')
}) })
message.channel.send('That word is banned here.').then((x)=>setTimeout(()=>x.delete(), 5000)); message.channel.send('That word is banned here.').then((x)=>setTimeout(()=>x.delete(), 5000));
if (client.repeatedMessages[message.author.id]){ if (client.repeatedMessages[message.author.id]){
@ -58,7 +58,7 @@ export default {
if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod)) { if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod)) {
automodded = true; automodded = true;
message.delete().catch((err)=>{ message.delete().catch((err)=>{
console.log('advertisement automod; msg got possibly deleted by another bot or moderator.') console.log('advertisement automod; msg got possibly deleted by another bot.')
}) })
} }

View File

@ -36,7 +36,7 @@ client.on('ready', async()=>{
// Handle errors // Handle errors
process.on('unhandledRejection', async(error: Error)=>{ process.on('unhandledRejection', async(error: Error)=>{
console.log(error); console.log(error);
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) //(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]})
}); });
process.on('uncaughtException', async(error: Error)=>{ process.on('uncaughtException', async(error: Error)=>{
console.log(error); console.log(error);
@ -62,9 +62,11 @@ setInterval(async()=>{
const newServerId = client.config.mainServer.id const newServerId = client.config.mainServer.id
const ServerURL = MPDB.findOne({where: {serverId: newServerId}}) const ServerURL = MPDB.findOne({where: {serverId: newServerId}})
const DBURL = (await ServerURL).ip const DBURL = (await ServerURL).ip
const DBCode = (await ServerURL).code // vv todo: strip 'http://' from ServerURL const DBCode = (await ServerURL).code
const verifyURL = DBURL.match(/http/);
const completedURL_DSS = DBURL + '/feed/dedicated-server-stats.json?code=' + DBCode const completedURL_DSS = DBURL + '/feed/dedicated-server-stats.json?code=' + DBCode
const completedURL_CSG = DBURL + '/feed/dedicated-server-savegame.html?code=' + DBCode + '&file=careerSavegame' const completedURL_CSG = DBURL + '/feed/dedicated-server-savegame.html?code=' + DBCode + '&file=careerSavegame'
if (!verifyURL) return msg.edit({content: 'Invalid gameserver IP, please update!', embeds: null})
console.log(DBURL + '\n' + DBCode) console.log(DBURL + '\n' + DBCode)
try { try {
Server = await client.axios.get(completedURL_DSS, {timeout: 4000}) Server = await client.axios.get(completedURL_DSS, {timeout: 4000})

View File

@ -9,6 +9,7 @@ class MPDB extends Model<InferAttributes<MPDB>, InferCreationAttributes<MPDB>>{
declare serverId: string | null; declare serverId: string | null;
declare ip: string | null; declare ip: string | null;
declare code: string | null; declare code: string | null;
declare timesUpdated: number | null;
} }
MPDB.init({ MPDB.init({
serverId: { serverId: {
@ -24,6 +25,12 @@ MPDB.init({
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: 'Missing Code', defaultValue: 'Missing Code',
allowNull: false allowNull: false
},
timesUpdated: {
type: DataTypes.INTEGER,
defaultValue: 0,
allowNull: false
} }
}, { sequelize: db, modelName: 'urls', timestamps: false }); }, { sequelize: db, modelName: 'urls', timestamps: false });
MPDB.sync();
export default MPDB export default MPDB