Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8e72ace
updated app version in package.json
vb2007 Oct 26, 2025
b58c362
updated app version in package-lock.json
vb2007 Oct 26, 2025
e0871d7
added release & deploy status badges to readme, removed codeql for now
vb2007 Oct 26, 2025
ba3fece
added back codeql badge
vb2007 Oct 26, 2025
762b015
deleted .vscode and .zed folders
vb2007 Oct 26, 2025
862acc7
updated .gitignore with ide specific folders
vb2007 Oct 26, 2025
0bc1fe2
created store.js
vb2007 Oct 27, 2025
7041917
created base for command
vb2007 Oct 30, 2025
32136f4
resolved merge conflict
vb2007 Nov 22, 2025
57f201c
fixed error in darwinCache table creation sql script
vb2007 Nov 22, 2025
7f634a3
updated darwinCache table definition
vb2007 Nov 23, 2025
d18b38e
updated version in package lock
vb2007 Nov 23, 2025
2bbafb1
created sql file for new economy store table
vb2007 Nov 23, 2025
39ee607
added execution logic for /store
vb2007 Nov 23, 2025
da37106
Fixed tokens & permissions in wiki update workflow
vb2007 Nov 23, 2025
127c28e
fixed permissions in rest of the workflows
vb2007 Nov 23, 2025
c5fa613
updated packages
vb2007 Nov 29, 2025
85f1880
changed bot's status to display current version
vb2007 Nov 29, 2025
4b1d24c
implemented economyStore sql table definition
vb2007 Nov 29, 2025
34e5a71
made name unique in economyStore
vb2007 Nov 30, 2025
e56f4c0
updated description & implemented query logic for /store
vb2007 Nov 30, 2025
4391830
added missing replyAndLog import
vb2007 Nov 30, 2025
c6b6712
added query mapping for displaying items correctly in embed response
vb2007 Nov 30, 2025
e0c326d
added economyStore.csv data file
vb2007 Nov 30, 2025
c27b0cc
created parseCSVLine, made a universal parseAndUpdateCSV function &
vb2007 Nov 30, 2025
6ee3fa1
removed id column processing from economyStore table update
vb2007 Nov 30, 2025
b356eeb
moved all QA badges to another line in readme
vb2007 Nov 30, 2025
aa39edd
added store to commandData
vb2007 Dec 1, 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
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Deploy
permissions: {}

permissions:
contents: read

on:
push:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Unit tests

permissions:
contents: read

on:
pull_request:
branches: [main, dev]
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/wiki-update.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Update Wiki Commands

permissions:
contents: write #gives both read & write access

on:
push:
branches: [main]
Expand Down Expand Up @@ -31,10 +34,10 @@ jobs:

- name: Update Wiki
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Clone wiki repo
git clone https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.wiki.git wiki
git clone https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.wiki.git wiki

# Copy new content
cp src/data/commands.md ./wiki/Commands.md
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Application specific files & folders
.env
config.json
/node_modules
/src/command-logs
/src/data/cigpics.json
/src/data/pics.json
/src/data/commands.md

# IDE / code editor specific folders
/.vscode
/.zed
41 changes: 0 additions & 41 deletions .vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

5 changes: 0 additions & 5 deletions .zed/settings.json

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

<div align="center">

[![Unit tests](https://github.com/vb2007/discordbot/actions/workflows/unit-tests.yml/badge.svg?branch=dev)](https://github.com/vb2007/discordbot/actions/workflows/unit-tests.yml) [![Update Wiki Commands](https://github.com/vb2007/discordbot/actions/workflows/wiki-update.yml/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/wiki-update.yml) [![CodeQL](https://github.com/vb2007/discordbot/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/github-code-scanning/codeql)
[![Deploy](https://github.com/vb2007/discordbot/actions/workflows/deploy.yml/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/deploy.yml) [![Release on GitHub](https://github.com/vb2007/discordbot/actions/workflows/gh-release.yml/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/gh-release.yml) [![Update Wiki Commands](https://github.com/vb2007/discordbot/actions/workflows/wiki-update.yml/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/wiki-update.yml)

</div>

<div align="center">

[![Unit tests](https://github.com/vb2007/discordbot/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/unit-tests.yml) [![CodeQL](https://github.com/vb2007/discordbot/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/vb2007/discordbot/actions/workflows/github-code-scanning/codeql)

</div>

Expand Down
36 changes: 17 additions & 19 deletions package-lock.json

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

41 changes: 41 additions & 0 deletions src/commands/economy/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { SlashCommandBuilder } from "discord.js";
import { embedReplyPrimaryColorWithFields } from "../../helpers/embeds/embed-reply.js";
import { checkIfNotInGuild } from "../../helpers/command-validation/general.js";
import { replyAndLog } from "../../helpers/reply.js";
import { query } from "../../helpers/db.js";

const commandName = "store";

export default {
data: new SlashCommandBuilder()
.setName(commandName)
.setDescription(
"Returns a store page with various purchaseable items that can help with your economy status."
)
.setNSFW(false)
.setDMPermission(false),
async execute(interaction) {
const guildCheck = checkIfNotInGuild(commandName, interaction);
if (guildCheck) {
return await replyAndLog(interaction, guildCheck);
}

const storeQuery = await query(
`SELECT name, price, description FROM economyStore ORDER BY price ASC`
);
const fields = storeQuery.map((item) => ({
name: `${item.name} - \`$${item.price}\``,
value: item.description,
inline: false,
}));

const embedReply = embedReplyPrimaryColorWithFields(
"Store",
"Use the `/buy`(**item name**) command to purchase any of these items.",
fields,
interaction
);

return await replyAndLog(interaction, embedReply);
},
};
86 changes: 60 additions & 26 deletions src/create-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,69 @@ const readSQLFiles = (dir) => {
return sqlQueries;
};

const updateCommandData = async () => {
//parses CSV line into array of values
const parseCSVLine = (line) => {
const regex = /(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,"]*))/g;
const values = [];
let match;

while ((match = regex.exec(line))) {
const value = match[1] || match[2];
values.push(value ? value.replace(/""/g, '"').trim() : "");
}

return values;
};

//universal function to parse and update CSV data into database tables
const parseAndUpdateCSV = async (csvFileName, tableName, columnMapping) => {
try {
const csvPath = path.join(__dirname, "data", "commandData.csv");
const csvPath = path.join(__dirname, "data", csvFileName);
const csvContent = fs.readFileSync(csvPath, "utf8");

const commands = csvContent
.split("\n")
//parse CSV and extract headers
const lines = csvContent.split("\n").filter((line) => line.trim());
const headers = parseCSVLine(lines[0]);

const rows = lines
.slice(1)
.filter((line) => line.trim())
.map((line) => {
//csv parsing
const regex = /(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,"]*))/g;
const values = [];
let match;
const values = parseCSVLine(line);

while ((match = regex.exec(line))) {
const value = match[1] || match[2];
values.push(value ? value.replace(/""/g, '"').trim() : "");
}
if (values.length < headers.length) return null;

if (values.length < 4) return null;
//create object with header-value pairs
const row = {};
headers.forEach((header, index) => {
row[header] = values[index];
});

const [id, name, category, description] = values;
return { name, category, description };
return row;
})
.filter((cmd) => cmd !== null);
.filter((row) => row !== null);

//prepare SQL query
const columns = columnMapping.columns;
const placeholders = columns.map(() => "?").join(", ");
const updateClause = columns
.filter((col) => !columnMapping.skipUpdate?.includes(col))
.map((col) => `${col} = VALUES(${col})`)
.join(", ");

for (const cmd of commands) {
console.log(`Processing command: ${cmd.name}`);
const insertQuery = `INSERT INTO ${tableName} (${columns.join(", ")}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${updateClause}`;

await query(
"INSERT INTO commandData (name, category, description) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE category = VALUES(category), description = VALUES(description)",
[cmd.name, cmd.category, cmd.description]
);
for (const row of rows) {
const identifier = row[columnMapping.identifier] || row.name || row.id;
console.log(`Processing ${tableName}: ${identifier}`);

const values = columns.map((col) => row[col]);

await query(insertQuery, values);
}

console.log("Command data has been updated successfully.");
console.log(`${tableName} data has been updated successfully.`);
} catch (error) {
console.error("Error updating command data:", error);
console.error(`Error updating ${tableName} data:`, error);
console.error("Error details:", error.stack);
}
};
Expand Down Expand Up @@ -106,7 +130,17 @@ const createTables = async () => {

const init = async () => {
await createTables();
await updateCommandData();

await parseAndUpdateCSV("commandData.csv", "commandData", {
columns: ["name", "category", "description"],
identifier: "name",
});

await parseAndUpdateCSV("economyStore.csv", "economyStore", {
columns: ["price", "name", "description"],
identifier: "name",
});

process.exit(0);
};

Expand Down
1 change: 1 addition & 0 deletions src/data/commandData.csv
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
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."
41,store,economy,Displays a store filled with various items / power-ups you can buy to help you progress in this terrible economy.
9 changes: 9 additions & 0 deletions src/data/economyStore.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"id","price","name","description"
1,5,Bread,"flour, yeast, salt, water. fresh."
2,150,gun,"Makes you able to rob from a user's bank account, if they haven't been bankrobbed already after their last deposit."
3,80,fentanyl,"Gives you a 100% success rate on your next rob command, unless your target has a police badge."
4,5000,clipped-coins,"Gets you expelled from 109 countries, but makes you gain a 3x multiplier on any gabling command you use first after activation."
5,15000,dildo,very long
6,2500,fried-chicken,"Best paired with watermelon & Kool-aid. Your black mind runs faster from it, thus giving you a 15% win rate on your next roulette game, if you bet on green."
7,100,police-badge,"Takes your opponent's breath instantly when it's under the influence of fent, thus making the robbery attempt unsuccessful."
8,150,kippah,"Makes your nose huge, but gives you a 3x multiplier on the next work commands."
Loading