From 7bee11e4f4302cc8d55c4dfaac9ea62e65dedd77 Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Fri, 24 Nov 2023 19:56:03 -0500 Subject: [PATCH] Initial work on BreadMixer --- bin/breadmixer.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ breadbot.js | 10 ++++----- utilities/sqlutil.js | 8 +++---- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 bin/breadmixer.py diff --git a/bin/breadmixer.py b/bin/breadmixer.py new file mode 100644 index 0000000..8c2dab5 --- /dev/null +++ b/bin/breadmixer.py @@ -0,0 +1,50 @@ +import argparse +import mysql.connector +import json +import os +import sys +import datetime + +argument_parser = argparse.ArgumentParser(description="BreadMixer is used to combine media from Discord Voice Calls") +argument_parser.add_argument("callid", help="The call id that needs to be mixed") +argument_parser.add_argument("config", help="The BreadBot config file location") + +args = argument_parser.parse_args() + +if not os.path.exists(args.config): + print('The file path {path} does not exist'.format(path=args.config)) + sys.exit(1) + +with open(args.config) as config: + json_config = json.loads(config.read()) + +config_must_contain = [ + "mysql_username", + "mysql_password", + "mysql_db_name", + "mysql_host", + "media_voice_folder" +] + +if not all([element in json_config for element in config_must_contain]): + print('One or more of the following config items are missing') + for element in config_must_contain: + print('\t{item}'.format(item=element)) + + sys.exit(2) + +mydb = mysql.connector.connect( + host=json_config["mysql_host"], + user=json_config["mysql_username"], + password=json_config["mysql_password"], + database=json_config["mysql_db_name"] +) + +cursor = mydb.cursor() + +cursor.execute("SELECT call_start_time FROM call_states WHERE call_id = %d", (args.callid)) + +call_start_time = cursor.fetchall() + +print(call_start_time) + diff --git a/breadbot.js b/breadbot.js index 48ae887..59d5762 100644 --- a/breadbot.js +++ b/breadbot.js @@ -2,14 +2,12 @@ const fs = require('node:fs'); const path = require('node:path'); const { Client, Events, GatewayIntentBits, Collection } = require('discord.js'); const { joinVoiceChannel, getVoiceConnection, entersState, VoiceConnectionStatus, EndBehaviorType } = require('@discordjs/voice') -const { token, mysql_username, mysql_password } = require('./config.json'); +const { token, media_voice_folder } = require('./config.json'); const sqlutil = require('./utilities/sqlutil'); const { Console } = require('node:console'); const prism = require('prism-media') - - -sqlutil.buildPool('breadbot_test') +sqlutil.buildPool() const getAllFiles = function(directoryPath, arrayOfFiles) { const files = fs.readdirSync(directoryPath); @@ -105,7 +103,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { console.log(`\tNext call ID ${newCallID}`) // This should always have something to do, as all callIDs should be unique - fs.mkdirSync("." + path.sep + "media" + path.sep + "voice_audio" + path.sep + newCallID, {recursive: true}) + fs.mkdirSync(media_voice_folder + path.sep + newCallID, {recursive: true}) const connection = joinVoiceChannel({ channelId: newState.channelId, @@ -136,7 +134,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { maxPackets: 10 } })) - .pipe(fs.createWriteStream("." + path.sep + "media" + path.sep + "voice_audio" + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`)) + .pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`)) }) } catch (error) { diff --git a/utilities/sqlutil.js b/utilities/sqlutil.js index 4090f2b..d906225 100644 --- a/utilities/sqlutil.js +++ b/utilities/sqlutil.js @@ -1,15 +1,15 @@ const mysql = require('mysql2') -const { mysql_username, mysql_password } = require('../config.json') +const { mysql_username, mysql_password, mysql_host, mysql_db_name } = require('../config.json') var connection_pool = null -async function buildPool(db_name) { +async function buildPool() { if (connection_pool == null) { connection_pool = mysql.createPool({ - host: "10.26.48.207", + host: mysql_host, user: mysql_username, password: mysql_password, - database: db_name, + database: mysql_db_name, connectionLimit: 10 }).promise() }