Tentative deploy

This commit is contained in:
Skylar Grant 2023-02-12 17:16:03 -05:00
parent e6aeb685ee
commit 2694d4b691
4 changed files with 59 additions and 29 deletions

View File

@ -138,5 +138,23 @@ module.exports = {
break; break;
} }
} }
generateSetupInfo() {
let setupInfoParts = [
`Here is your server's configuration:`,
`Tree Name: ${this.treeName}`,
`Tree Height: ${this.treeHeight}`,
`Tree Channel: <#${this.treeChannelId}>`,
`[Tree Link](https://discord.com/channels/${this.guildId}/${this.treeChannelId}/${this.treeMessageId})`,
`Leaderboard Channel: <#${this.leaderboardChannelId}>`,
`[Leaderboard Link](https://discord.com/channels/${this.guildId}/${this.leaderboardChannelId}/${this.leaderboardMessageId})`,
`Notification Watch Channel: <#${this.watchChannelId}>`,
`Notification Relay Channel: <#${this.reminderChannelId}>`,
`Water Message: ${this.waterMessage}`,
`Fruit Message: ${this.fruitMessage}`,
`Water Role: <@&${this.waterRoleId}>`,
`Fruit Role: <@&${this.fruitRoleId}>`
]
return setupInfoParts.join('\n');
}
} }
} }

View File

@ -145,6 +145,35 @@ module.exports = {
}); });
}); });
}, },
setTreeInfo(guildInfo) {
const db = mysql.createConnection({
host: process.env.DBHOST,
user: process.env.DBUSER,
password: process.env.DBPASS,
database: process.env.DBNAME,
port: process.env.DBPORT
});
db.connect((err) => {
if (err) throw `Error connecting to the database: ${err.message}`;
});
// Returns a Promise, resolve({ "status": "", "data": null })
// guildInfo = { "guildId": "123", "treeName": "name", "treeHeight": 123, "treeMessageId": "123", "treeChannelId": "123", "leaderboardMessageId": "123", "leaderboardChannelId": "123"}
// Set a server's tree information in the database)
const insertGuildInfoQuery = `INSERT INTO guild_info (guild_id, tree_name, tree_height, tree_message_id, tree_channel_id) VALUES (${db.escape(guildInfo.guildId)}, ${db.escape(guildInfo.treeName)}, ${db.escape(guildInfo.treeHeight)},${db.escape(guildInfo.treeMessageId)}, ${db.escape(guildInfo.treeChannelId)}) ON DUPLICATE KEY UPDATE tree_name = ${db.escape(guildInfo.treeName)},tree_height = ${db.escape(guildInfo.treeHeight)},tree_message_id = ${db.escape(guildInfo.treeMessageId)},tree_channel_id = ${db.escape(guildInfo.treeChannelId)}`;
// TODO run this query and return a promise, then resolve with { "status": , "data": null }
return new Promise((resolve, reject) => {
db.query(insertGuildInfoQuery, (err, res) => {
if (err) {
console.error(err);
db.end();
reject("Error setting the guild info: " + err.message);
return;
}
db.end();
resolve({ "status": "Successfully set the guild information", "data": null });
});
});
},
setLeaderboardInfo(guildInfo) { setLeaderboardInfo(guildInfo) {
const db = mysql.createConnection({ const db = mysql.createConnection({
host: process.env.DBHOST, host: process.env.DBHOST,

View File

@ -549,13 +549,6 @@ const functions = {
}); });
}); });
}, },
getInfo(interaction) {
let guildInfo = interaction.client.guildInfos.get(interaction.guild.id);
let guildInfoString = "";
guildInfoString += `Tree Message: https://discord.com/channels/${guildId}/${guildInfo.treeChannelId}/${guildInfo.treeMessageId}\n`;
guildInfoString += `Rank Message: https://discord.com/channels/${guildId}/${guildInfo.leaderboardChannelId}/${guildInfo.leaderboardMessageId}\n`;
return `Here is your servers setup info:\n${guildInfoString}`;
},
getWaterTime(size) { getWaterTime(size) {
return Math.floor(Math.pow(size * 0.07 + 5, 1.1)); // Seconds return Math.floor(Math.pow(size * 0.07 + 5, 1.1)); // Seconds
}, },
@ -602,17 +595,6 @@ const functions = {
console.error(err); console.error(err);
}); });
}, },
async refreshComparisonMessage(client, guildInfo) {
if (guildInfo.comparisonChannelId != "" && guildInfo.comparisonMessageId != "") {
const guild = await client.guilds.fetch(guildInfo.guildId);
const comparisonChannel = await guild.channels.fetch(guildInfo.comparisonChannelId);
const comparisonMessage = await comparisonChannel.messages.fetch(guildInfo.comparisonMessageId);
const embed = comparisonMessage.embeds[0];
const actionRow = this.builders.actionRows.comparisonActionRow(guildInfo);
await comparisonMessage.edit({ components: [actionRow] });
return;
}
},
async setupCollectors(client) { async setupCollectors(client) {
let guildInfos = client.guildInfos; let guildInfos = client.guildInfos;
guildInfos.set("collectors", []); guildInfos.set("collectors", []);

View File

@ -5,17 +5,18 @@ module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('setupinfo') .setName('setupinfo')
.setDescription('View information about how the bot is set up in your server'), .setDescription('View information about how the bot is set up in your server'),
execute(interaction) { async execute(interaction) {
interaction.deferReply({ephemeral: true}).then(() => { await interaction.deferReply({ ephemeral: true }).catch(err => console.error(err));
fn.getInfo(interaction).then(res => { try {
const embed = fn.builders.embed(res); if (interaction.client.guildInfos.has(interaction.guildId)) {
interaction.editReply(embed); let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
}).catch(err => { await interaction.editReply(fn.builders.embed(guildInfo.generateSetupInfo()));
interaction.editReply(err); } else {
await interaction.editReply(fn.builders.errorEmbed("Guild doesn't exist in database!"));
}
} catch (err) {
console.error(err); console.error(err);
}); await interaction.editReply(fn.builders.errorEmbed("There was an error running the command."));
}).catch(err => { }
console.error(err);
});
}, },
}; };