Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stuff work #45

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Binary file added bun.lockb
Binary file not shown.
8 changes: 5 additions & 3 deletions buttonrow.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MessageActionRow } from "discord.js"
import { ActionRowBuilder, ButtonBuilder } from "discord.js"

export default class ButtonRow {

constructor(options, ...buttons) {
this.options = options
this.row = new MessageActionRow()
this.row = new ActionRowBuilder()
.addComponents(buttons)
this.msg = null
this.disabled = false
Expand Down Expand Up @@ -40,7 +40,9 @@ export default class ButtonRow {
editRow(cb) {
if(!cb || this.disabled) return
this.editOptions(msg => {
let row = msg.components[0]
console.log(msg.components[0]);
let row = msg.components[0];
row.components = row.components.map(component => ButtonBuilder.from(component))
cb(row)
return { components: [row] }
})
Expand Down
4 changes: 2 additions & 2 deletions commands/game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageEmbed } from "discord.js";
import { EmbedBuilder } from "discord.js";
import { games } from "../lyrics.js";
import Game from "../game.js"

Expand Down Expand Up @@ -53,7 +53,7 @@ export default {
run: async (bot, interaction) => {
const sub = interaction.options.getSubcommand();
if(sub === "list") {
const embed = new MessageEmbed();
const embed = new EmbedBuilder();
embed.setTitle("Songs (" + lyrics.length + ")");
embed.setFooter("SongGuesser");
embed.setColor([0, 230, 0]);
Expand Down
6 changes: 3 additions & 3 deletions commands/points.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageEmbed } from "discord.js";
import { EmbedBuilder } from "discord.js";
import points from "../points.js";

export default {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default {
const user = interaction.options.getUser("user") || interaction.user;
const point = points.getPoints(user.id, interaction.guild.id);
console.log(point);
const embed = new MessageEmbed();
const embed = new EmbedBuilder();
embed.setTitle(`${user.username}'s points`);
embed.setFooter("SongGuesser");
embed.setColor("YELLOW");
Expand All @@ -58,7 +58,7 @@ export default {
return;
}
const top = global ? points.getTopList() : points.getTopList(interaction.guild.id);
const embed = new MessageEmbed();
const embed = new EmbedBuilder();
embed.setTitle("Top list for " + (global ? "all guilds" : interaction.guild.name));
embed.setFooter("SongGuesser");
embed.setColor("#3cbd9b");
Expand Down
2 changes: 1 addition & 1 deletion commands/round.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageEmbed } from "discord.js";
import { EmbedBuilder } from "discord.js";
import { games } from "../lyrics.js";
import Game from "../game.js"

Expand Down
46 changes: 23 additions & 23 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import Logger from "./logger.js"
import { bot, getFooter } from "./main.js"
import Round from "./round.js"
import ButtonRow from "./buttonrow.js"
import config from "./config.json" assert {type: "json"};
import points from "./points.js"
import { ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
import { readFile } from "fs/promises"

export const config = await readFile("./config.json", { encoding: "utf-8" }).then(JSON.parse);

const logger = new Logger("Game")

Expand Down Expand Up @@ -60,27 +63,24 @@ export default class Game {
}]
}

this.buttonrow = new ButtonRow(msgopt, {
customId: `join_game`,
disabled: false,
emoji: { name: `🎶` },
label: "Tune in",
style: "PRIMARY",
type: "BUTTON"
}, {
customId: `quickstart_game`,
disabled: true,
emoji: { name: `⏩` },
label: "Quickstart",
style: "SUCCESS",
type: "BUTTON"
}, {
customId: `cancel_game`,
disabled: false,
label: "Cancel",
style: "DANGER",
type: "BUTTON"
})
this.buttonrow = new ButtonRow(msgopt, new ButtonBuilder()
.setCustomId("join_game")
.setDisabled(false)
.setEmoji("🎶")
.setLabel("Tune in")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId("quickstart_game")
.setDisabled(true)
.setEmoji("⏩")
.setLabel("Quickstart")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId("cancel_game")
.setDisabled(false)
.setLabel("Cancel")
.setStyle(ButtonStyle.Danger)
)

if(interaction) this.buttonrow.reply(interaction)
else this.buttonrow.send(this.channel)
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class Game {

if(this.buttonrow && this.state == Game.STARTING) {
this.buttonrow.editOptions(msg => {
let embed = msg.embeds[0]
let embed = EmbedBuilder.from(msg.embeds[0])
embed.fields = [{name: `Participants (${this.participantCount}/${minParticipants}):`, value: this.participantlist.join(", ")}]
return {embeds: [embed]}
})
Expand Down
6 changes: 3 additions & 3 deletions lyrics.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from "fs/promises"
import { readFile } from "fs/promises"
import ytdl from "ytdl-core"
import Logger from "./logger.js"
import { COLOR } from "./logger.js"
import Game from "./game.js"
import config from "./config.json" assert {type: "json"}

export const config = await readFile("./config.json", { encoding: "utf-8" }).then(JSON.parse);

const lyricslib = await import(config.lyrics + "main.mjs")

Expand Down Expand Up @@ -40,7 +41,6 @@ export default class LyricsMan {
})

bot.on("interactionCreate", i => {
if(i.type != "MESSAGE_COMPONENT") return
if(!i.isButton()) return
if(!["join_game","quickstart_game","cancel_game"].includes(i.customId)) return

Expand Down
9 changes: 5 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Client, WebhookClient } from "discord.js";
import config from "./config.json" assert {type: "json"};
import { Client, GatewayIntentBits, Partials, WebhookClient } from "discord.js";
import { load, register } from "./commands.js"
import statusmgr from "./statusmgr.js"
import LyricsMan from "./lyrics.js"
import Logger from "./logger.js"
import { COLOR } from "./logger.js"
import points from "./points.js";
import { db, createTables } from "./sql.js";
import fs from "fs/promises"
import fs, { readFile } from "fs/promises"
cfpwastaken marked this conversation as resolved.
Show resolved Hide resolved
import { execSync } from "child_process"

export const config = await readFile("./config.json", { encoding: "utf-8" }).then(JSON.parse);

export let errorhook = null;
if(config.errorhook) {
errorhook = new WebhookClient({ url: config.errorhook });
Expand Down Expand Up @@ -42,7 +43,7 @@ if(config.errorhook) {
}

const logger = new Logger("Discord Bot", "38;2;255;0;255;3")
export const bot = new Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "DIRECT_MESSAGES"], partials: ["CHANNEL"] });
export const bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages], partials: [Partials.Channel] });

export const VERSION = await getVersion()
export const BRANCH = getBranch()
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
"license": "ISC",
"dependencies": {
"@discordjs/opus": "^0.8.0",
"@discordjs/rest": "^0.4.1",
"@discordjs/voice": "^0.9.0",
"discord-api-types": "^0.33.0",
"discord.js": "^13.7.0",
"discord.js": "^14.15.2",
"ffmpeg-static": "^5.0.0",
"mysql2": "^2.3.3",
"opusscript": "^0.1.1",
"prism-media": "^1.3.4",
"sodium": "^3.0.2",
"ytdl-core": "^4.11.2"
}
},
"trustedDependencies": [
"sodium"
]
}
18 changes: 9 additions & 9 deletions points.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Points {

this.points = new Map() // userid -> points
this.guildpoints = new Map() // guildid -> (userid -> points)
db.query("SELECT * FROM users").then(rows => {
for(const row of rows[0]) {
if(!this.points.has(row.id)) this.points.set(row.id + "", row.points);
else this.points.set(row.id, this.points.get(row.id + "") + row.points)
const guild = this.guildpoints.get(row.guild) || new Map()
guild.set(row.id, row.points)
this.guildpoints.set(row.guild, guild)
}
});
// db.query("SELECT * FROM users").then(rows => {
// for(const row of rows[0]) {
// if(!this.points.has(row.id)) this.points.set(row.id + "", row.points);
// else this.points.set(row.id, this.points.get(row.id + "") + row.points)
// const guild = this.guildpoints.get(row.guild) || new Map()
// guild.set(row.id, row.points)
// this.guildpoints.set(row.guild, guild)
// }
// });

}

Expand Down
19 changes: 11 additions & 8 deletions sql.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import Logger from "./logger.js"
import { COLOR } from "./logger.js"
import mysql from "mysql2/promise";
import config from "./config.json" assert {type: "json"};
import { readFile } from "fs/promises";

export const config = await readFile("./config.json", { encoding: "utf-8" }).then(JSON.parse);

const logger = new Logger("MySQL", COLOR.DARK_AQUA)
logger.log("Starting MySQL")
export let db = await mysql.createConnection({
host: config.mysql.host,
user: config.mysql.user,
password: config.mysql.password,
database: config.mysql.database
});
// export let db = await mysql.createConnection({
// host: config.mysql.host,
// user: config.mysql.user,
// password: config.mysql.password,
// database: config.mysql.database
// });
export let db;
logger.log("Connected to MySQL")
createTables();
// createTables();

export async function createTables() {
await db.query(`CREATE TABLE IF NOT EXISTS users (
Expand Down
4 changes: 3 additions & 1 deletion statusmgr.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { bot } from "./main.js"
import activities from "./status.json" assert {type: "json"}
import Logger from "./logger.js"
import { COLOR } from "./logger.js"
import { lyrics } from "./lyrics.js"
import { readFile } from "fs/promises";

export const activities = await readFile("./status.json", { encoding: "utf-8" }).then(JSON.parse);

const logger = new Logger("StatusMgr", COLOR.LIGHT_YELLOW)

Expand Down