Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1ca24d6
updated packages
vb2007 Nov 10, 2025
3ad40c3
created darwin-random command
vb2007 Nov 10, 2025
f81cb0f
created base logic to reply helper
vb2007 Nov 11, 2025
9f70609
updated cdn url in example config json
vb2007 Nov 12, 2025
55d597f
updated reply helper, started formatting message
vb2007 Nov 13, 2025
d658209
renamed, added columns to darwinCache table
vb2007 Nov 13, 2025
618dc45
created word-leaderboard.js command file
vb2007 Nov 20, 2025
b0d96aa
created command builder for new command
vb2007 Nov 20, 2025
ad00c9b
added guild check
vb2007 Nov 20, 2025
d394b82
updated packages
vb2007 Nov 20, 2025
d2af319
started implementation with query, added missing import
vb2007 Nov 20, 2025
8003525
commented out other debug darwin logs
vb2007 Nov 20, 2025
aab83c0
fixed errors in new command
vb2007 Nov 20, 2025
f803002
fixed sql query
vb2007 Nov 20, 2025
796a3e7
updated imports, started writing embed reply
vb2007 Nov 20, 2025
457acd0
commented out messageCreate console logs
vb2007 Nov 20, 2025
f8699b9
added 1st part of the description to embed builder
vb2007 Nov 20, 2025
31a85b0
updated embed description formatting
vb2007 Nov 20, 2025
a893529
deleted already executed migration script
vb2007 Nov 20, 2025
69e3035
added logic for displaying leaderboard
vb2007 Nov 20, 2025
47962d3
fixed promise error
vb2007 Nov 20, 2025
ef9875c
fixed undefined error
vb2007 Nov 20, 2025
e346dca
moved positionEmojis to format helper
vb2007 Nov 20, 2025
ffc3ef5
changed reply method to deferReply to avoid timeouts
vb2007 Nov 20, 2025
5368c39
removed debug console logging
vb2007 Nov 20, 2025
80d50cc
added word-leaderboard to commandData
vb2007 Nov 21, 2025
d9aabb2
Merge pull request #172 from vb2007/dev-word-leaderboard
vb2007 Nov 21, 2025
fff5f82
fixed merge conflict
vb2007 Nov 21, 2025
3d1f08c
fixed merge conflict in package-lock
vb2007 Nov 21, 2025
453bc33
fixed query in /darwin-random
vb2007 Nov 21, 2025
98c4314
updated message format & query
vb2007 Nov 21, 2025
cc9009e
updated column name in sql file
vb2007 Nov 21, 2025
205dabc
fixed var name in reply helper, updated messageContent formatting
vb2007 Nov 21, 2025
77b37e1
updated processedAt time formatting
vb2007 Nov 21, 2025
fa17c8d
changed processedAt formatting to relative time
vb2007 Nov 21, 2025
1c5c042
removed unused imports
vb2007 Nov 22, 2025
22dc904
removed debug logging
vb2007 Nov 22, 2025
df3dbbd
updated packages
vb2007 Nov 22, 2025
97127ae
made title bold in darwinProcess
vb2007 Nov 22, 2025
a10adea
fdiscord
vb2007 Nov 22, 2025
bceda53
updated darwinCache table schema declaration from prod db DDL
vb2007 Nov 22, 2025
2f1b8d6
removed unneded config values from example config.json file
vb2007 Nov 22, 2025
5c43936
updated commandData + fixed auto increment
vb2007 Nov 22, 2025
ea4f2e8
bumped version number in package.json
vb2007 Nov 22, 2025
a16e0a4
fixed trigger in wiki update workflow
vb2007 Nov 22, 2025
3bae206
Merge pull request #173 from vb2007/dev-darwin-random
vb2007 Nov 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/wiki-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Update Wiki Commands

on:
push:
branches:
- main
branches: [main]
paths:
- "src/data/commandData.csv"
workflow_dispatch:
Expand Down
6 changes: 1 addition & 5 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
"feedUrl" : "https://theync.com/most-recent/",
"interval" : 120000,
"markerOne" : "https://theync.com/media/video",
"markerTwo" : "https://theync.com",
"maxDownloadSize" : 50,
"targetDir" : "/path/to/videos/folder",
"tempDir" : "/path/to/videos/folder/transcodes",
"cdnUrl" : "https://cdn.vb2007.hu/darwin/"
"markerTwo" : "https://theync.com"
}
}
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discordbot",
"version": "4.2.0",
"version": "4.2.1",
"description": "A simple discord bot of mine developed with discord.js (Node.js).",
"type": "module",
"main": "index.js",
Expand Down
33 changes: 33 additions & 0 deletions src/commands/fun/darwin-random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { SlashCommandBuilder } from "discord.js";
import { query } from "../../helpers/db.js";
import { baseReplyAndLog } from "../../helpers/reply.js";

export default {
data: new SlashCommandBuilder()
.setName("darwin-random")
.setDescription("Sends back a random, streamable video from Darwin's database.")
.setNSFW(false) //should be true, but fucking discord forces id checks to view NSFW channel. i won't comply.
.setDMPermission(true),
async execute(interaction) {
const randomVideo = await query(
`SELECT directVideoUrl, forumPostUrl, videoTitle, processedAt
FROM darwinCache
WHERE forumPostUrl IS NOT NULL
AND videoTitle IS NOT NULL
ORDER BY RAND()
LIMIT 1`
);

const directVideoUrl = randomVideo[0].directVideoUrl;
const forumPostUrl = randomVideo[0].forumPostUrl;
const videoTitle = randomVideo[0].videoTitle;
const processedAt = Math.floor(new Date(randomVideo[0].processedAt).getTime() / 1000);

const messageContent =
`[[ STREAMING & DOWNLOAD ]](${directVideoUrl}) - [[ FORUM POST ]](<${forumPostUrl}>)\n` +
`**Title**: ${videoTitle}\n` +
`**Processed at**: <t:${processedAt}:R>`;

await baseReplyAndLog(interaction, messageContent);
},
};
74 changes: 74 additions & 0 deletions src/commands/fun/word-leaderboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { SlashCommandBuilder } from "discord.js";
import { embedReplyPrimaryColor } from "../../helpers/embeds/embed-reply.js";
import { positionEmojis } from "../../helpers/format.js";
import { checkIfNotInGuild } from "../../helpers/command-validation/general.js";
import { logToFileAndDatabase } from "../../helpers/logger.js";
import { query } from "../../helpers/db.js";

const commandName = "word-leaderboard";

export default {
data: new SlashCommandBuilder()
.setName(commandName)
// Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most.
.setDescription(
"Gives back a word count leaderboard with the top users who used that word the most."
)
.addStringOption((option) =>
option
.setName("word")
.setDescription("The word that will get counted.")
.setRequired(true)
.setMinLength(2)
.setMaxLength(12)
)
.setDMPermission(false),
async execute(interaction) {
await interaction.deferReply();

const guildCheck = checkIfNotInGuild(commandName, interaction);
if (guildCheck) {
return await replyAndLog(interaction, guildCheck);
}

const targetWord = interaction.options.getString("word");
const currentServerId = interaction.guild.id;

const usersQuery = await query(
`SELECT senderUserId, senderUserName, COUNT(*) as wordCount
FROM messageLog
WHERE serverId = ? AND messageContent LIKE ?
GROUP BY senderUserId
ORDER BY wordCount DESC
LIMIT 10`,
[currentServerId, `%${targetWord}%`]
);

let leaderboardContent = "";
for (let i = 0; i < usersQuery.length; i++) {
const userResult = usersQuery[i];
const emoji = positionEmojis[i + 1];

let username;
try {
const member = await interaction.guild.members.fetch(userResult.senderUserId);
username = member.user.username;
} catch (error) {
username = userResult.senderUserName || "Unknown username";
}

leaderboardContent += `${emoji} <@${userResult.senderUserId}> (${username}): **#${userResult.wordCount}**\n`;
}

const embedReply = embedReplyPrimaryColor(
`Word Leaderboard: "${targetWord}"`,
usersQuery.length !== 0
? `Leaderboard of users whose messages contained the word **${targetWord}** the most:\n\n${leaderboardContent}`
: `:x: No user has used the word **${targetWord}** in their messages so far.`,
interaction
);

await interaction.editReply({ embeds: [embedReply] });
await logToFileAndDatabase(interaction, JSON.stringify(embedReply.toJSON()));
},
};
26 changes: 14 additions & 12 deletions src/data/commandData.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
24,ban,moderation,Bans a specified member from the server.
25,purge,moderation,Purges (mass deletes) a specified amount of messages from the current channel.
26,config-autorole,administration,"Sets / modifies / disables the autorole feature. When a new member joins the server, a specified role will get assigned to them automatically."
28,config-welcome,administration,"Sets / modifies / disables the welcome messages feature. When a new member joins the server, the bot send a specified welcome message."
30,config-logging,administration,Sets / modifies / disables the channel where event on the server will get logged
32,config-bridge,administration,Sets / modifies / disables bridging all messages from one channel to another.
34,rename,administration,Renames a specified user to a specified nickname in the current server.
35,slowmode,administration,Sets / disables the slowmode for a specified channel.
36,config-goodbye,administration,"Sets / modifies / disables the goodbye messages feature. When a member leaves the server, the bot send a specified goodbye message."
82,coinflip-fun,fun,Flips a coin that has a 50/50 chance landing on heads or tails. Has an economy (*/coinflip*) version with gambling.
112,blackjack,economy,Lets you play a game of blackjack with a specified amount. You can pick **Hit** or **Stand** until the player or the house wins
192,config-darwin,administration,Sets / modifies / disables Darwin's occasional video scraping & posting feature.
193,cigany,fun,"Says ""fuj"" and sends a random pic of a ""person"" from a specific race."
194,cooldown,economy,Lets you check your or other users economy cooldowns for all or a specified economy command.
195,invite,utility,Gives you back a link for inviting the bot to any server where you have permissions to do so.
27,config-welcome,administration,"Sets / modifies / disables the welcome messages feature. When a new member joins the server, the bot send a specified welcome message."
28,config-logging,administration,Sets / modifies / disables the channel where event on the server will get logged
29,config-bridge,administration,Sets / modifies / disables bridging all messages from one channel to another.
30,rename,administration,Renames a specified user to a specified nickname in the current server.
31,slowmode,administration,Sets / disables the slowmode for a specified channel.
32,config-goodbye,administration,"Sets / modifies / disables the goodbye messages feature. When a member leaves the server, the bot send a specified goodbye message."
33,coinflip-fun,fun,Flips a coin that has a 50/50 chance landing on heads or tails. Has an economy (*/coinflip*) version with gambling.
34,blackjack,economy,Lets you play a game of blackjack with a specified amount. You can pick **Hit** or **Stand** until the player or the house wins
35,config-darwin,administration,Sets / modifies / disables Darwin's occasional video scraping & posting feature.
36,cigany,fun,"Says ""fuj"" and sends a random pic of a ""person"" from a specific race."
37,cooldown,economy,Lets you check your or other users economy cooldowns for all or a specified economy command.
38,invite,utility,Gives you back a link for inviting the bot to any server where you have permissions to do so.
39,word-leaderboard,fun,Counts a specified word in the current server and sends back a leaderboard with the users who used that word the most through all their previous messages.
40,darwin-random,fun,"Sends back a random, streamable video from Darwin's database."
6 changes: 3 additions & 3 deletions src/events/scripts/messageCreate/messageLogging.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const logToDB = async (message) => {
]
);

console.log(
`Logged message "${message.content}" to database from ${senderUserName} in ${serverName}.`
);
// console.log(
// `Logged message "${message.content}" to database from ${senderUserName} in ${serverName}.`
// );
}
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/darwin/darwinCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const addToCache = async (directVideoUrl, forumPostUrl, videoTitle) => {
try {
const exists = await isInCache(directVideoUrl);
if (exists) {
console.log(`URL already in cache: ${directVideoUrl}`);
// console.log(`URL already in cache: ${directVideoUrl}`);
return true;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export const addToCache = async (directVideoUrl, forumPostUrl, videoTitle) => {
export const isInCache = async (url) => {
try {
const videoId = extractVideoId(url);
console.log(`Checking "${url}" (ID: ${videoId}) in Darwin's cache`);
// console.log(`Checking "${url}" (ID: ${videoId}) in Darwin's cache`);

const result = await query(
"SELECT directVideoUrl FROM darwinCache WHERE directVideoUrl = ? OR videoId = ?",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/darwin/darwinProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const getVideoLocation = async (href, markerOne, markerTwo) => {
* @returns {string} - Formatted message
*/
const messageGen = (title, href, comments) => {
return `[[ STREAMING & DOWNLOAD ]](${href}) - [[ FORUM POST ]](<${comments}>)\n${title}`;
return `[[ STREAMING & DOWNLOAD ]](${href}) - [[ FORUM POST ]](<${comments}>)\n**${title}**`;
};

/**
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ export const formatRouletteColor = (color) => {
console.error("The color you've provided for the formatRouletteColor() function is invalid.");
}
};

export const positionEmojis = {
1: ":first_place:",
2: ":second_place:",
3: ":third_place:",
4: ":number_4:",
5: ":number_5:",
6: ":number_6:",
7: ":number_7:",
8: ":number_8:",
9: ":number_9:",
10: ":number_10:",
};
5 changes: 5 additions & 0 deletions src/helpers/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export const replyAndLog = async (interaction, embedReply) => {
await interaction.reply({ embeds: [embedReply] });
await logToFileAndDatabase(interaction, JSON.stringify(embedReply.toJSON()));
};

export const baseReplyAndLog = async (interaction, messageContent) => {
await interaction.reply(messageContent);
await logToFileAndDatabase(interaction, messageContent);
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ client.once(Events.ClientReady, (readyClient) => {

setInterval(() => {
if (darwinProcessRunning) {
console.log("Darwin process already running, skipping this execution");
// console.log("Darwin process already running, skipping this execution");
return;
}

Expand Down
14 changes: 0 additions & 14 deletions src/sql/darwinCache/migrate-to-new-schema.sql

This file was deleted.

19 changes: 10 additions & 9 deletions src/sql/darwinCache/table.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
-- discordbot.darwinCache definition

CREATE TABLE IF NOT EXISTS `darwinCache` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`directVideoUrl` VARCHAR(255) NOT NULL,
`forumPostUrl` VARCHAR(255) NOT NULL,
`videoId` VARCHAR(100) NOT NULL,
`videoTitle` VARCHAR(180) NOT NULL,
`processedAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY (`directVideoUrl`),
UNIQUE KEY (`videoId`)
CREATE TABLE `darwinCache` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`directVideoUrl` varchar(255) NOT NULL,
`forumPostUrl` varchar(255) NOT NULL DEFAULT '',
`videoId` varchar(100) NOT NULL,
`videoTitle` varchar(180) NOT NULL DEFAULT '',
`processedAt` timestamp NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `videoId` (`videoId`),
UNIQUE KEY `directVideoUrl` (`directVideoUrl`)
);
Loading