b724229f06
* make the beginning height optional, defaulting to the trees current heigt * improved workflow * fix * new fix * Install modules * remove unnecessary call to build the tables * testing * f * f * oops * undev * fix const * new ci * versioning * Classes, Collections, and new Notification Relay * Fix CI for new env vars * Update to read contents of embeds * Update filter to check for embeds * Update to add includes check * Begin implementing role menu * Role menu ready for testing * Add missing emojis * Fixes, ready for testing * Tentative deploy * Documentation update * I think this fixes unchanging notifications * Update README.md * Make reminders visually distinct * Set Permissions * Added import for PermissionFlagsBits * Add ability to manually send ping from watch chan * CI update * Confusion * Make dev dockerization manual only * Dev Logging * Update reset command * Implement updating of notifications piecemeal * Unified error handling * Change to refresh commands not blindly update * Change to manual run only * Restructured file to allow async use * Move role menu setup and allow everyone to send it * Consolidate setupinfo into setup * Improved error handling * Update opt out method * Cleaning up junk * Added seconds parser and optout detection * Add opt out method * Consolidated to setup command * Add privacy setting and use new parser
179 lines
8.4 KiB
JavaScript
Executable File
179 lines
8.4 KiB
JavaScript
Executable File
const mysql = require('mysql');
|
|
const db = mysql.createConnection({
|
|
host: process.env.DBHOST,
|
|
user: process.env.DBUSER,
|
|
password: process.env.DBPASS,
|
|
database: process.env.DBNAME,
|
|
port: process.env.DBPORT
|
|
});
|
|
|
|
module.exports = {
|
|
GuildInfo: class {
|
|
constructor() {
|
|
this.guildId = "";
|
|
this.treeName = "";
|
|
this.treeHeight = 0;
|
|
this.treeMessageId = "";
|
|
this.treeChannelId = "";
|
|
this.leaderboardMessageId = "";
|
|
this.leaderboardChannelId = "";
|
|
this.waterMessage = "";
|
|
this.waterRoleId = "";
|
|
this.fruitMessage = "";
|
|
this.fruitRoleId = "";
|
|
this.reminderChannelId = "";
|
|
this.watchChannelId = "";
|
|
this.notificationsEnabled = false;
|
|
}
|
|
|
|
setId(id) {
|
|
this.guildId = id;
|
|
return this;
|
|
}
|
|
setName(name) {
|
|
this.treeName = name;
|
|
return this;
|
|
}
|
|
setHeight(height) {
|
|
this.treeHeight = height;
|
|
return this;
|
|
}
|
|
setTreeMessage(messageId, channelId) {
|
|
this.treeMessageId = messageId;
|
|
this.treeChannelId = channelId;
|
|
return this;
|
|
}
|
|
setLeaderboardMessage(messageId, channelId) {
|
|
this.leaderboardMessageId = messageId;
|
|
this.leaderboardChannelId = channelId;
|
|
return this;
|
|
}
|
|
setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) {
|
|
if (waterMessage) this.waterMessage = waterMessage;
|
|
if (fruitMessage) this.fruitMessage = fruitMessage;
|
|
if (reminderChannelId) this.reminderChannelId = reminderChannelId;
|
|
if (watchChannelId) this.watchChannelId = watchChannelId;
|
|
if (enabled) this.notificationsEnabled = enabled;
|
|
return this;
|
|
}
|
|
setRoles(waterRoleId, fruitRoleId) {
|
|
this.waterRoleId = waterRoleId;
|
|
if (fruitRoleId) this.fruitRoleId = fruitRoleId;
|
|
return this;
|
|
}
|
|
queryBuilder(query) {
|
|
let queryParts = [];
|
|
switch (query) {
|
|
case "setAll":
|
|
queryParts = [
|
|
`INSERT INTO guild_info `,
|
|
`(guild_id, `,
|
|
`tree_name, `,
|
|
`tree_height, `,
|
|
`tree_message_id, `,
|
|
`tree_channel_id, `,
|
|
`leaderboard_message_id, `,
|
|
`leaderboard_channel_id, `,
|
|
`water_message, `,
|
|
`fruit_message, `,
|
|
`reminder_channel_id, `,
|
|
`watch_channel_id) `,
|
|
`VALUES (${db.escape(this.guildId)}, `,
|
|
`${db.escape(this.treeName)}, `,
|
|
`${db.escape(this.treeHeight)}, `,
|
|
`${db.escape(this.treeMessageId)}, `,
|
|
`${db.escape(this.treeChannelId)}, `,
|
|
`${db.escape(this.leaderboardMessageId)}, `,
|
|
`${db.escape(this.leaderboardChannelId)}, `,
|
|
`${db.escape(this.waterMessage)}, `,
|
|
`${db.escape(this.fruitMessage)}, `,
|
|
`${db.escape(this.reminderChannelId)}, `,
|
|
`${db.escape(this.watchChannelId)}) `,
|
|
`ON DUPLICATE KEY UPDATE tree_name = ${db.escape(this.treeName)}, `,
|
|
`tree_height = ${db.escape(this.treeHeight)}, `,
|
|
`tree_message_id = ${db.escape(this.treeMessageId)}, `,
|
|
`tree_channel_id = ${db.escape(this.treeChannelId)}, `,
|
|
`leaderboard_message_id = ${db.escape(this.leaderboardMessageId)}, `,
|
|
`leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)}, `,
|
|
`water_message = ${db.escape(this.waterMessage)}, `,
|
|
`fruit_message = ${db.escape(this.fruitMessage)}, `,
|
|
`reminder_channel_id = ${db.escape(this.reminderChannelId)}, `,
|
|
`watch_channel_id = ${db.escape(this.watchChannelId)})`
|
|
];
|
|
return queryParts.join('');
|
|
break;
|
|
case "setReminders":
|
|
queryParts = [
|
|
`INSERT INTO guild_info (guild_id, water_message, fruit_message, reminder_channel_id, watch_channel_id, notifications_enabled) VALUES (`,
|
|
`${db.escape(this.guildId)},`,
|
|
`${db.escape(this.waterMessage)},`,
|
|
`${db.escape(this.fruitMessage)},`,
|
|
`${db.escape(this.reminderChannelId)},`,
|
|
`${db.escape(this.watchChannelId)},`,
|
|
`${db.escape(this.notificationsEnabled)}`,
|
|
`) ON DUPLICATE KEY UPDATE water_message = ${db.escape(this.waterMessage)}, `,
|
|
`fruit_message = ${db.escape(this.fruitMessage)}, `,
|
|
`reminder_channel_id = ${db.escape(this.reminderChannelId)}, `,
|
|
`watch_channel_id = ${db.escape(this.watchChannelId)},`,
|
|
`notifications_enabled = ${db.escape(this.notificationsEnabled)}`
|
|
];
|
|
return queryParts.join('');
|
|
break;
|
|
case "setTreeMessage":
|
|
queryParts = [
|
|
`UPDATE guild_info SET tree_message_id = ${db.escape(this.treeMessageId)}, `,
|
|
`tree_channel_id = ${db.escape(this.treeChannelId)}, `,
|
|
`WHERE guild_id = ${db.escape(this.guildId)}`
|
|
];
|
|
return queryParts.join('');
|
|
break;
|
|
case "setLeaderboardMessage":
|
|
queryParts = [
|
|
`UPDATE guild_info SET leaderboard_message_id = ${db.escape(this.leaderboardMessageId)}, `,
|
|
`leaderboard_channel_id = ${db.escape(this.leaderboardChannelId)}, `,
|
|
`WHERE guild_id = ${db.escape(this.guildId)}`
|
|
];
|
|
return queryParts.join('');
|
|
break;
|
|
case "setRoles":
|
|
if (this.fruitRoleId != "") {
|
|
queryParts = [
|
|
`INSERT INTO guild_info (`,
|
|
`guild_id, water_role_id, fruit_role_id`,
|
|
`) VALUES (`,
|
|
`${db.escape(this.guildId)}, ${db.escape(this.waterRoleId)}, ${db.escape(this.fruitRoleId)}`,
|
|
`) ON DUPLICATE KEY UPDATE water_role_id = ${db.escape(this.waterRoleId)}, `,
|
|
`fruit_role_id = ${db.escape(this.fruitRoleId)}`
|
|
];
|
|
} else {
|
|
queryParts = [
|
|
`UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)} `,
|
|
`WHERE guild_id = ${db.escape(this.guildId)}`
|
|
];
|
|
}
|
|
return queryParts.join('');
|
|
break;
|
|
default:
|
|
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');
|
|
}
|
|
}
|
|
} |