Initial work on BreadMixer
This commit is contained in:
parent
2954d1b304
commit
7bee11e4f4
50
bin/breadmixer.py
Normal file
50
bin/breadmixer.py
Normal file
@ -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)
|
||||
|
10
breadbot.js
10
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) {
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user