Last active
January 2, 2020 05:38
-
-
Save ChaseIngebritson/e3f3b2d38c35a5d416fe7395152bf3cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Attachment } from 'discord.js' | |
import puppeteer from 'puppeteer' | |
import { splitMessage } from '../utils.js' | |
export default async (msg) => { | |
const input = splitMessage(msg) | |
let target | |
if (input.args.length > 0) { | |
const target = await msg.channel.fetchMessage(input.args[0]) | |
if (!target) { | |
msg.reply('Send me a valid message ID dickhead.') | |
} | |
// const recording = await getRecording() | |
// const music = recordingToMusic(recording) | |
// const attachment = new Attachment(music) | |
// msg.reply(attachment) | |
} else { | |
target = msg.channel.messages.last(2)[0] | |
const recording = await getRecording() | |
const attachment = new Attachment(Buffer.from(recording), 'test.mp3') | |
msg.reply(attachment) | |
} | |
} | |
async function getRecording (input) { | |
const browser = await puppeteer.launch({ | |
headless: false, | |
args: ['--no-sandbox'] | |
}) | |
const page = await browser.newPage() | |
await page.addScriptTag({ path: './node_modules/tone/build/tone.js' }) | |
let output = await page.evaluate(async () => { | |
const Tone = window.Tone | |
const output = await Tone.Offline((Transport) => { | |
var osc = new Tone.Oscillator().toMaster() | |
Transport.schedule((time) => { | |
osc.start(time).stop(time + 0.1) | |
}, 1) | |
Transport.start(0.2) | |
}, 4) | |
return [...output.toMono().toArray()] | |
}) | |
// await browser.close() | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment