Skip to content

Commit

Permalink
update dumps path
Browse files Browse the repository at this point in the history
  • Loading branch information
Moebits committed Aug 23, 2024
1 parent 8f8f9dc commit 75cb71b
Show file tree
Hide file tree
Showing 28 changed files with 63 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ assets/images/dump/*
assets/images/waifu2x/*
assets/misc/videos/*
assets/misc/tracks/*
assets/misc/images/*
assets/misc/dump/*

#Other
Expand Down
Binary file removed assets/images/captcha.png
Binary file not shown.
Binary file modified assets/images/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/in.jpg
Binary file not shown.
Binary file removed assets/images/out.jpg
Binary file not shown.
Binary file removed assets/images/welcomeBG.jpg
Binary file not shown.
Binary file removed assets/images/wiki.png
Binary file not shown.
4 changes: 2 additions & 2 deletions commands/anime/ugoira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class Ugoira extends Command {

setTimeout(() => msg1.delete(), 1000)
const ugoiraEmbed = embeds.createEmbed()
const outGif = new AttachmentBuilder(path.join(__dirname, `../../../assets/images/gifs/${pixivID}.gif`))
const outGif = new AttachmentBuilder(path.join(__dirname, `../../assets/misc/images/gifs/${pixivID}.gif`))
const comments = await pixiv.illust.comments({illust_id: pixivID as number})
const cleanText = details.caption.replace(/<\/?[^>]+(>|$)/g, "")
const authorUrl = await pixiv.util.downloadProfilePicture(details, `assets/images/pixiv/profiles`)
Expand Down Expand Up @@ -152,7 +152,7 @@ export default class Ugoira extends Command {
rep.delete()
if (bad) return
await pixiv.util.downloadUgoira(String(pixivID), `assets/images/gifs/`, {speed: factor, reverse: setReverse})
const outGif = new AttachmentBuilder(path.join(__dirname, `../../../assets/images/gifs/${pixivID}.gif`))
const outGif = new AttachmentBuilder(path.join(__dirname, `../../assets/misc/images/gifs/${pixivID}.gif`))
await message.channel.send({files: [outGif]})
})
}
Expand Down
4 changes: 2 additions & 2 deletions commands/level/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export default class Rank extends Command {
ctx.fillStyle = "#ff3d9b"
ctx.fillRect(0, 0, width, 5)
const dataUrl = canvas.toDataURL()
let image = path.join(__dirname, `../../../assets/images/dump/rankBar.jpg`)
let image = path.join(__dirname, `../../assets/misc/images/dump/rankBar.jpg`)
let i = 1
while (fs.existsSync(image)) {
image = path.join(__dirname, `../../../assets/images/dump/rankBar${i}.jpg`)
image = path.join(__dirname, `../../assets/misc/images/dump/rankBar${i}.jpg`)
i++
}
await imageDataURI.outputFile(dataUrl, image)
Expand Down
4 changes: 2 additions & 2 deletions commands/misc 2/hastebin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export default class Hastebin extends Command {
const textFile = await discord.fetchLastAttachment(message, false, /.(txt|ts|js|json|py|html|css|less|scss|tsx|jsx|c|cs|cpp|java|xml)/)
if (textFile) {
const ext = path.extname(textFile).replace(".", "")
let dest = path.resolve(__dirname, `../../../assets/misc/dump/hastebin.${ext}`)
let dest = path.resolve(__dirname, `../../assets/misc/dump/hastebin.${ext}`)
let i = 1
while (fs.existsSync(dest)) {
dest = path.resolve(__dirname, `../../../assets/misc/dump/hastebin${i}.${ext}`)
dest = path.resolve(__dirname, `../../assets/misc/dump/hastebin${i}.${ext}`)
i++
}
await images.download(textFile, dest)
Expand Down
4 changes: 2 additions & 2 deletions commands/misc 2/pastebin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export default class Pastebin extends Command {
const {image, author} = await discord.fetchLastAttachment(message, true, /.(txt|ts|js|json|py|html|css|less|scss|tsx|jsx|c|cs|cpp|java|xml)/)
if (image) {
const ext = path.extname(image).replace(".", "")
let dest = path.resolve(__dirname, `../../../assets/misc/dump/pastebin.${ext}`)
let dest = path.resolve(__dirname, `../../assets/misc/dump/pastebin.${ext}`)
let i = 1
while (fs.existsSync(dest)) {
dest = path.resolve(__dirname, `../../../assets/misc/dump/pastebin${i}.${ext}`)
dest = path.resolve(__dirname, `../../assets/misc/dump/pastebin${i}.${ext}`)
i++
}
await images.download(image, dest)
Expand Down
4 changes: 2 additions & 2 deletions commands/misc/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export default class Download extends Command {
return message.channel.send({embeds: [downloadEmbed]})
}
const rand = Math.floor(Math.random()*10000)
const src = path.join(__dirname, `../../../assets/images/dump/${rand}/`)
const src = path.join(__dirname, `../../assets/misc/images/dump/${rand}/`)
if (!fs.existsSync(src)) fs.mkdirSync(src)
const dest = path.join(__dirname, `../../../assets/images/dump/${rand}/${name}.zip`)
const dest = path.join(__dirname, `../../assets/misc/images/dump/${rand}/${name}.zip`)
await i.downloadImages(images, src)
const downloads = fs.readdirSync(src).map((m) => src + m)
await Functions.createZip(downloads, dest)
Expand Down
2 changes: 1 addition & 1 deletion commands/misc/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class Upload extends Command {
const images = new Images(this.discord, message)
const notify = await sql.fetchColumn("images", "notify toggle")
const channel = message.guild?.channels.cache.find((c: GuildBasedChannel) => c.id === guildChannel) as TextChannel
const dest = path.join(__dirname, `../../../assets/images/dump/${channel.name}/`)
const dest = path.join(__dirname, `../../assets/misc/images/dump/${channel.name}/`)
if (!fs.existsSync(dest)) fs.mkdirSync(dest, {recursive: true})
let done = false
let counter = 0
Expand Down
2 changes: 1 addition & 1 deletion commands/music 3/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class Record extends Command {
const loading = message.channel.lastMessage
loading?.delete()
const recording = connection.receiver.subscribe(message.author.id, {end: {behavior: EndBehaviorType.AfterSilence, duration: 1000}})
const pcm = path.join(__dirname, `../../../assets/misc/tracks/${name}.pcm`)
const pcm = path.join(__dirname, `../../assets/misc/tracks/${name}.pcm`)
await message.channel.send(`Recording started! Please use **push to talk**, the recording will stop once the push button is released.`)
await new Promise<void>((resolve) => {
recording.pipe(fs.createWriteStream(pcm) as unknown as NodeJS.WritableStream).on("finish", () => resolve())
Expand Down
4 changes: 2 additions & 2 deletions commands/video/crunchydl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class CrunchyDL extends Command {
} catch {
return message.reply(`Sorry, there was an error with processing this request. Try again later.`)
}
const folder = path.join(__dirname, `../../../assets/misc/videos/${vilos.series}`)
const folder = path.join(__dirname, `../../assets/misc/videos/${vilos.series}`)
if (!fs.existsSync(folder)) fs.mkdirSync(folder, {recursive: true})
const dest = path.join(folder, `./${vilos.title}.mp4`)
const episodeNum = Number(url.match(/(?<=episode-)(.*?)(?=-)/)?.[0])
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class CrunchyDL extends Command {
)
} else {
const data = await axios.get(vilos.subtitles[0].url, {headers: this.headers}).then((r) => r.data)
const subDest = path.join(__dirname, `../../../assets/misc/dump/${vilos.title}.txt`)
const subDest = path.join(__dirname, `../../assets/misc/dump/${vilos.title}.txt`)
fs.writeFileSync(subDest, data)
attachment = new AttachmentBuilder(subDest)
crunchyEmbed
Expand Down
2 changes: 1 addition & 1 deletion commands/video/gifspeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class ConstrainGIF extends Command {
if (constrain >= frames.length) return message.reply(`Adding frames to or slowing down a gif is not supported, because it requires more information than what is available in the original. ${discord.getEmoji("kannaFacepalm")}`)
const newFrames = Functions.constrain(frames, constrain) as any[]
const random = Math.floor(Math.random() * 10000)
const dir = path.join(__dirname, `../../../assets/images/dump/${random}/`)
const dir = path.join(__dirname, `../../assets/misc/images/dump/${random}/`)
if (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true})
const files: string[] = []
const promises: any[] = []
Expand Down
5 changes: 3 additions & 2 deletions commands/website 2/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Functions} from "./../../structures/Functions"
import {Images} from "./../../structures/Images"
import {Kisaragi} from "./../../structures/Kisaragi"
import {ProcBlock} from "./../../structures/ProcBlock"
import path from "path"

let ytEmbeds: EmbedBuilder[] = []
export default class YoutubeCommand extends Command {
Expand Down Expand Up @@ -217,7 +218,7 @@ export default class YoutubeCommand extends Command {
.setAuthor({name: "youtube", iconURL: "https://cdn4.iconfinder.com/data/icons/social-media-2210/24/Youtube-512.png", url: "https://www.youtube.com/"})
.setTitle(`**Youtube Download** ${discord.getEmoji("kannaWave")}`))
}
const src = `../assets/misc/videos/${rand}/`
const src = path.join(__dirname, `../../assets/misc/tracks/${rand}/`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
const msg2 = await message.channel.send(`**Downloading MP3, this will take awhile, please be patient** ${discord.getEmoji("gabCircle")}`) as Message
let file: string
Expand Down Expand Up @@ -266,7 +267,7 @@ export default class YoutubeCommand extends Command {
.setAuthor({name: "youtube", iconURL: "https://cdn4.iconfinder.com/data/icons/social-media-2210/24/Youtube-512.png", url: "https://www.youtube.com/"})
.setTitle(`**Youtube Download** ${discord.getEmoji("kannaWave")}`))
}
const src = `../assets/misc/videos/${rand}/`
const src = path.join(__dirname, `../../assets/misc/videos/${rand}/`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
const msg2 = await message.channel.send(`**Downloading video, this will take awhile, please be patient** ${discord.getEmoji("gabCircle")}`) as Message
let file: string
Expand Down
3 changes: 2 additions & 1 deletion commands/website/soundcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Audio} from "./../../structures/Audio"
import {Embeds} from "./../../structures/Embeds"
import {Images} from "./../../structures/Images"
import {Kisaragi} from "./../../structures/Kisaragi"
import path from "path"

export default class SoundCloud extends Command {
private user = null as any
Expand Down Expand Up @@ -131,7 +132,7 @@ export default class SoundCloud extends Command {
.setTitle(`**Soundcloud Search** ${discord.getEmoji("karenSugoi")}`))
}
const rand = Math.floor(Math.random()*10000)
const src = `../assets/misc/tracks/${rand}/`
const src = path.join(__dirname, `../../assets/misc/tracks/${rand}/`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
let track: string
if (/soundcloud.com/.test(query)) {
Expand Down
4 changes: 2 additions & 2 deletions commands/website/wikipedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export default class Wikipedia extends Command {

if (mainImg.slice(-3) === "svg") {
await svg2img(mainImg, function(error: Error, buffer: Buffer) {
fs.writeFileSync(path.join(__dirname, "../../../assets/images/dump/wiki.png"), buffer)
fs.writeFileSync(path.join(__dirname, "../../assets/misc/images/dump/wiki.png"), buffer)
})

await Functions.timeout(500)

const attachment = new AttachmentBuilder(path.join(__dirname, "../../../assets/images/dump/wiki.png"))
const attachment = new AttachmentBuilder(path.join(__dirname, "../../assets/misc/images/dump/wiki.png"))

const wikiEmbed = embeds.createEmbed()
wikiEmbed
Expand Down
4 changes: 2 additions & 2 deletions events/guildMemberSpeaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export default class GuildMemberSpeaking {
return message.reply(`Voice recognition has a **10** second cooldown ${discord.getEmoji("no")}`)
}
const recording = connection.receiver.createStream(member.id, {mode: "pcm", end: "silence"})
const pcm = path.join(__dirname, `../../assets/misc/tracks/${member.user.tag}_voice.pcm`)
const pcm = path.join(__dirname, `../assets/misc/tracks/${member.user.tag}_voice.pcm`)
await new Promise<void>((resolve) => {
recording.pipe(fs.createWriteStream(pcm)).on("finish", () => resolve())
})
let wavDest = await fx.pcmToWav(pcm, true)
wavDest = path.join(__dirname, `.${wavDest}`)
// const wavDest = path.join(__dirname, "../../assets/misc/tracks/hello.wav")
// const wavDest = path.join(__dirname, "../assets/misc/tracks/hello.wav")
const buffer = fs.readFileSync(wavDest, null)
const headers = {"authorization": `Bearer ${process.env.WITAI_API_KEY}`, "content-type": "audio/wav"}
const speech = await axios.post(`https://api.wit.ai/speech`, buffer, {headers}).then((r) => r.data._text)
Expand Down
31 changes: 16 additions & 15 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@ const discord = new Kisaragi({
DefaultWebSocketManagerOptions.identifyProperties.browser = "Discord iOS"

const dumps = [
`../assets/images/dump`,
`../assets/images/gifs`,
`../assets/images/misc`,
`../assets/images/pages`,
`../assets/images/pixiv/illusts`,
`../assets/images/pixiv/profiles`,
`../assets/images/pixiv/zip`,
`../assets/images/waifu2x`,
`../assets/misc/dump`,
`../assets/misc/tracks`,
`../assets/misc/videos`,
`./tracks/transform`,
`./images/transform`,
`./videos/transform`
`./assets/misc/images/dump`,
`./assets/misc/images/gifs`,
`./assets/misc/images/misc`,
`./assets/misc/images/pages`,
`./assets/misc/images/pixiv/illusts`,
`./assets/misc/images/pixiv/profiles`,
`./assets/misc/images/pixiv/zip`,
`./assets/misc/images/waifu2x`,
`./assets/misc/dump`,
`./assets/misc/tracks`,
`./assets/misc/videos`,
`./assets/misc/tracks/transform`,
`./assets/misc/images/transform`,
`./assets/misc/videos/transform`
]

for (let i = 0; i < dumps.length; i++) {
if (!fs.existsSync(path.join(__dirname, dumps[i]))) fs.mkdirSync(path.join(__dirname, dumps[i]), {recursive: true})
Functions.removeDirectory(path.join(__dirname, "./assets/misc"))
fs.mkdirSync(path.join(__dirname, dumps[i]), {recursive: true})
}

const start = async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion structures/Audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mp3Duration from "mp3-duration"
import path from "path"
import Soundcloud from "soundcloud.ts"
import Youtube from "youtube.ts"
import defaults from "./../assets/json/defaultSongs.json"
import defaults from "../assets/json/defaultSongs.json"
import {AudioEffects} from "./AudioEffects"
import {Embeds} from "./Embeds"
import {Functions} from "./Functions"
Expand Down
6 changes: 3 additions & 3 deletions structures/AudioEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ export class AudioEffects {
filepath = dest
}
const inDest = await this.convertToFormat(filepath, "aiff")
// const ext = path.extname(filepath).replace(".", "")
fileDest = fileDest.replace(/(_)(.*?)(?=_)/g, "")
let outDest = fileDest.slice(0, -4) + `.aiff`
let index = 0
while (fs.existsSync(outDest)) {
/*while (fs.existsSync(outDest)) {
outDest = index <= 1 ? `${fileDest}.aiff` : `${fileDest}${index}.aiff`
index++
}
}*/
const command = `"${soxPath}" "${inDest}" "${outDest}" gain -50 ${effect} gain -n -1`
const child = child_process.exec(command)
await new Promise<void>((resolve) => {
child.on("error", (err) => console.log(err))
child.on("close", () => resolve())
})
const mp3Dest = await this.convertToFormat(outDest, "mp3")
if (filepath.includes("tracks/transform")) fs.unlink(filepath, () => null)
fs.unlink(inDest, () => null)
fs.unlink(outDest, () => null)
return mp3Dest
Expand Down
4 changes: 2 additions & 2 deletions structures/Captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export class Captcha {
})

await svg2img(captcha.data, function(error: Error, buffer: Buffer) {
fs.writeFileSync(path.join(__dirname, "../../assets/images/captcha.png"), buffer)
fs.writeFileSync(path.join(__dirname, "../assets/misc/images/captcha.png"), buffer)
})

const attachment = new AttachmentBuilder(path.join(__dirname, "../../assets/images/captcha.png"), {name: "captcha.png"})
const attachment = new AttachmentBuilder(path.join(__dirname, "../assets/misc/images/captcha.png"), {name: "captcha.png"})

const captchaEmbed = this.embeds.createEmbed()
captchaEmbed
Expand Down
12 changes: 6 additions & 6 deletions structures/Embeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export class Embeds {
}
const rep = await msg.channel.send(`<@${user.id}>, **Downloading the images, please wait** ${this.discord.getEmoji("gabCircle")}`)
const rand = Math.floor(Math.random()*10000)
const src = path.join(__dirname, `../../assets/images/dump/${rand}/`)
const dest = path.join(__dirname, `../../assets/images/dump/${rand}.zip`)
const src = path.join(__dirname, `../assets/misc/images/dump/${rand}/`)
const dest = path.join(__dirname, `../assets/misc/images/dump/${rand}.zip`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
await this.images.downloadImages(images, src)
const downloads = fs.readdirSync(src).map((m) => src + m)
Expand Down Expand Up @@ -340,8 +340,8 @@ export class Embeds {
}
const rep = await msg.channel.send(`<@${user.id}>, **Downloading the images, please wait** ${this.discord.getEmoji("gabCircle")}`)
const rand = Math.floor(Math.random()*10000)
const src = path.join(__dirname, `../../assets/images/dump/${rand}/`)
const dest = path.join(__dirname, `../../assets/images/dump/${rand}.zip`)
const src = path.join(__dirname, `../assets/misc/images/dump/${rand}/`)
const dest = path.join(__dirname, `../assets/misc/images/dump/${rand}.zip`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
await this.images.downloadImages(images, src)
const downloads = fs.readdirSync(src).map((m) => src + m)
Expand Down Expand Up @@ -444,8 +444,8 @@ export class Embeds {
}
const rep = await msg.channel.send(`<@${user.id}>, **Downloading the images, please wait** ${this.discord.getEmoji("gabCircle")}`)
const rand = Math.floor(Math.random()*10000)
const src = path.join(__dirname, `../../assets/images/dump/${rand}/`)
const dest = path.join(__dirname, `../../assets/images/dump/${rand}.zip`)
const src = path.join(__dirname, `../assets/misc/images/dump/${rand}/`)
const dest = path.join(__dirname, `../assets/misc/images/dump/${rand}.zip`)
if (!fs.existsSync(src)) fs.mkdirSync(src, {recursive: true})
await this.images.downloadImages(images, src)
const downloads = fs.readdirSync(src).map((m) => src + m)
Expand Down
6 changes: 3 additions & 3 deletions structures/Images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Images {
/** Compresses a gif. */
public compressGif = async (input: string[]) => {
const file = await imagemin(input,
{destination: path.join(__dirname, "../../assets/images/gifs"),
{destination: path.join(__dirname, "../assets/misc/images/gifs"),
plugins: [imageminGifsicle({interlaced: false, optimizationLevel: 2, colors: 512})]
})
return file
Expand Down Expand Up @@ -244,7 +244,7 @@ export class Images {
let background: Canvas.Image
if (image.includes("gif")) {
const random = Math.floor(Math.random() * 1000000)
const dir = path.join(__dirname, `../../assets/images/dump/${random}/`)
const dir = path.join(__dirname, `../assets/misc/images/dump/${random}/`)
if (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true})

const files: string[] = []
Expand Down Expand Up @@ -426,7 +426,7 @@ export class Images {

/** Upload attachment to Twitter */
public uploadTwitterMedia = async (twitter: Twitter, link: string) => {
const src = await this.downloadImage(link, path.join(__dirname, `../../assets/misc/dump/${link.slice(-10)}`))
const src = await this.downloadImage(link, path.join(__dirname, `../assets/misc/dump/${link.slice(-10)}`))
let mime = "image/jpeg"
if (/.png/.test(src)) {
mime = "image/png"
Expand Down
Loading

0 comments on commit 75cb71b

Please sign in to comment.