Compare commits

...

12 Commits

Author SHA1 Message Date
Skylar Grant ac6eca4827 Merge pull request 'v1.2.9-dev' (#8) from v1.2.9-dev into main
Reviewed-on: #8
2024-04-06 13:16:15 +00:00
Skylar Grant 88cc4eda3c Remove reminder embed, only send text message
Silvanus Production Dockerization / build (pull_request) Has been cancelled Details
2024-04-06 09:01:57 -04:00
Skylar Grant 7291216dcb Versioning 2024-04-06 09:01:43 -04:00
Skylar Grant 36f44f4b41 Merge pull request 'v1.2.8 Heartbeat Monitoring' (#6) from v1.2.8 into main
Reviewed-on: #6
2023-09-02 08:37:11 -07:00
Skylar Grant 825ec725d1 Timer planning
Silvanus Production Dockerization / build (pull_request) Has been cancelled Details
2023-09-02 09:42:10 -04:00
Skylar Grant fb43d09d13 Fix debug mode detection
Silvanus Production Dockerization / build (pull_request) Has been cancelled Details
2023-08-27 20:27:11 -04:00
Skylar Grant 0463695323 Improved logging
Silvanus Production Dockerization / build (pull_request) Successful in 12s Details
2023-08-27 19:34:15 -04:00
Skylar Grant 314b793042 Versioning
Silvanus Production Dockerization / build (pull_request) Successful in 53s Details
2023-08-10 22:18:28 -04:00
Skylar Grant eca3207d4e Remove excess console.log 2023-08-10 22:16:23 -04:00
Skylar Grant e2658c41e5 Add heartbeat url for uptime monitoring 2023-08-10 22:13:08 -04:00
Skylar Grant dd313faa60 Merge pull request 'Change dispatch to pull req' (#3) from testing into main
Reviewed-on: #3
2023-08-04 09:52:53 -07:00
Skylar Grant 4dda58f48e Merge pull request 'Slight verbiage change' (#2) from testing into main
Reviewed-on: #2
2023-07-31 12:58:33 -07:00
5 changed files with 48 additions and 18 deletions

View File

@ -5,5 +5,4 @@ WORKDIR /usr/src/app
COPY package.json ./ COPY package.json ./
RUN npm install RUN npm install
COPY . . COPY . .
# CMD ["/bin/sh", "-c", "node main.js 2> /logs/silvanus.err 1> /logs/silvanus.log"] CMD ["/bin/sh", "-c", "node main.js 2>&1 > /logs/$(date +%Y-%m-%d_%H-%M-%S).txt"]
CMD ["/bin/sh", "-c", "node main.js 2> /logs/error/$(date +%Y-%m-%d_%H-%M-%S).txt 1> /logs/status/$(date +%Y-%m-%d_%H-%M-%S).txt"]

24
TODO.md
View File

@ -1,10 +1,3 @@
## In Progress
☑ Switch `/setup` to ask for the tree and leaderboard channels
* Switch `/compare` to check for newer trees and leaderboards when run **and** on every refresh
## Future Ideas
* Go through and comment the code
## Variable Structures ## Variable Structures
guildInfo = { guildInfo = {
@ -21,7 +14,18 @@ guildInfo = {
reminderOptIn: 0, reminderOptIn: 0,
} }
## Expected Behaviors ## New Table Planning
Table: `silvanus`.timers
* Run `/compare` before `/setup`: `/compare` will search the current channel for tree and leaderboard messages, then create a comparison embed. If it can't find `/tree` or `/top trees` messages, it'll return an error saying as much. id | INT | NOT NULL | AUTO INCREMENT | PRIMARY KEY
* Run `/compare` after `/setup`: ``/compare` will search the current channel for tree and leaderboard messages, then create a comparison embed. If it can't find `/tree` or `/top trees` messages, it'll just use old data silently (odds are `/compare` is being run from another channel, that's fine) status | VARCHAR(10) | NOT NULL | DEFAULT "WAITING"
dc_timecode | INT | NOT NULL | Discord timecode
guild_id | INT UNSIGNED | NOT NULL | Discord guild ID for referencing `silvanus`.guildInfo
Table: `silvanus`.auto_role_status
id | INT | NOT NULL | AUTO INCREMENT | PRIMARY KEY
user_id | INT UNSIGNED | NOT NULL
guild_id | INT UNSIGNED | NOT NULL
status | VARCHAR(10) | NOT NULL | DEFAULT "REMOVED" | OPTION: {"REMOVED", "ADDED"}

14
main.js
View File

@ -5,6 +5,8 @@ const dotenv = require('dotenv');
dotenv.config(); dotenv.config();
const token = process.env.TOKEN; const token = process.env.TOKEN;
const statusChannelId = process.env.STATUSCHANNELID; const statusChannelId = process.env.STATUSCHANNELID;
const heartbeatUrl = process.env.HEARTBEAT_URL;
const sendHeartbeat = typeof heartbeatUrl === 'string';
// Discord.JS // Discord.JS
const { Client, GatewayIntentBits, Partials, ActivityType } = require('discord.js'); const { Client, GatewayIntentBits, Partials, ActivityType } = require('discord.js');
@ -26,7 +28,7 @@ const fn = require('./modules/functions.js');
const strings = require('./data/strings.json'); const strings = require('./data/strings.json');
const dbfn = require('./modules/dbfn.js'); const dbfn = require('./modules/dbfn.js');
const { GuildInfo } = require('./modules/CustomClasses.js'); const { GuildInfo } = require('./modules/CustomClasses.js');
const isDev = process.env.DEBUG; const isDev = process.env.DEBUG === "true";
let statusChannel; let statusChannel;
client.once('ready', async () => { client.once('ready', async () => {
@ -43,6 +45,16 @@ client.once('ready', async () => {
if (isDev == 'false') { if (isDev == 'false') {
statusChannel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`); statusChannel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`);
} }
// Heartbeat Timer
if (sendHeartbeat) {
setInterval(() => {
fn.sendHeartbeat(heartbeatUrl);
}, 30000);
if (isDev) console.log("Heartbeat interval set.");
} else {
if (isDev) console.log("No heartbeat URL set, will not send heartbeats for uptime monitoring.");
}
}); });
// slash-commands // slash-commands

View File

@ -20,6 +20,7 @@ const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => fil
const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js')); const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js'));
const dbfn = require('./dbfn.js'); const dbfn = require('./dbfn.js');
const { finished } = require('stream'); const { finished } = require('stream');
const https = require('https');
const functions = { const functions = {
// Functions for managing and creating Collections // Functions for managing and creating Collections
@ -1045,9 +1046,9 @@ const functions = {
}, },
async sendWaterReminder(guildInfo, message, channelId, guild) { async sendWaterReminder(guildInfo, message, channelId, guild) {
const reminderChannel = await guild.channels.fetch(channelId); const reminderChannel = await guild.channels.fetch(channelId);
const reminderEmbed = functions.builders.waterReminderEmbed(message, guildInfo); // const reminderEmbed = functions.builders.waterReminderEmbed(message, guildInfo);
if (isDev) console.log(`WR: ${guild.name}: ${guildInfo.treeName}`); if (isDev) console.log(`WR: ${guild.name}: ${guildInfo.treeName}`);
await reminderChannel.send(reminderEmbed).then(async m => { await reminderChannel.send(message).then(async m => {
if (!m.deletable) return; if (!m.deletable) return;
await this.sleep(500).then(async () => { await this.sleep(500).then(async () => {
await m.delete().catch(e => console.error(e)); await m.delete().catch(e => console.error(e));
@ -1058,9 +1059,9 @@ const functions = {
}, },
async sendFruitReminder(guildInfo, message, channelId, guild) { async sendFruitReminder(guildInfo, message, channelId, guild) {
const reminderChannel = await guild.channels.fetch(channelId); const reminderChannel = await guild.channels.fetch(channelId);
const reminderEmbed = functions.builders.fruitReminderEmbed(message, guildInfo); // const reminderEmbed = functions.builders.fruitReminderEmbed(message, guildInfo);
if (isDev) console.log(`FR: ${guild.name}: ${guildInfo.treeName}`); if (isDev) console.log(`FR: ${guild.name}: ${guildInfo.treeName}`);
await reminderChannel.send(reminderEmbed).then(async m => { await reminderChannel.send(message).then(async m => {
if (!m.deletable) return; if (!m.deletable) return;
await this.sleep(500).then(async () => { await this.sleep(500).then(async () => {
await m.delete().catch(e => console.error(e)); await m.delete().catch(e => console.error(e));
@ -1142,6 +1143,20 @@ const functions = {
} }
const errorId = digits.join(""); const errorId = digits.join("");
return errorId; return errorId;
},
async sendHeartbeat(url) {
https.get(url, async (response) => {
if (isDev) console.log("Sent Heartbeat Request: " + url);
let data = '';
response.on('data', (chunk) => data += chunk);
response.on('end', () => {
if (isDev) console.log("Received Heartbeat Response: " + data);
parsedData = JSON.parse(data);
if ( !(parsedData.ok) ) console.error("Heartbeat failed");
});
}).on("error", (error) => console.error(error));
} }
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "silvanus", "name": "silvanus",
"version": "1.2.7", "version": "1.2.9",
"description": "Grow A Tree Companion Bot", "description": "Grow A Tree Companion Bot",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {