-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eb37f8
commit b88f51f
Showing
5 changed files
with
97 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Formats a number of bytes into a human-readable string representation. | ||
* | ||
* @param {number} bytes - The number of bytes to format. | ||
* @param {Object} [options={}] - Formatting options. | ||
* @param {boolean} [options.bits=false] - If true, format the bytes as bits. | ||
* @param {boolean} [options.signed=false] - If true, include a plus sign for positive values when using the signed format. | ||
* @param {string} [options.locale='en'] - The locale to use for formatting. Can be 'en' (English) or 'de' (German). | ||
* @returns {string} The formatted byte size string. | ||
*/ | ||
|
||
module.exports = (bytes, options = {}) => { | ||
const { bits = false, signed = false, locale = "en" } = options; | ||
|
||
const units = bits | ||
? ["b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"] | ||
: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; | ||
|
||
const kilo = bits ? 1024 : 1000; | ||
const isNegative = signed && bytes < 0; | ||
const num = isNegative ? -bytes : bytes; | ||
|
||
if (num < 1) { | ||
return (isNegative ? "-" : "") + num + " " + units[0]; | ||
} | ||
|
||
const exponent = Math.min( | ||
Math.floor(Math.log10(num) / Math.log10(kilo)), | ||
units.length - 1 | ||
); | ||
const value = (num / Math.pow(kilo, exponent)).toFixed(2); | ||
|
||
const formattedValue = locale === "en" ? value : value.replace(".", ","); | ||
|
||
return (isNegative ? "-" : "") + formattedValue + " " + units[exponent]; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
//make a simple discord.js client | ||
const Discord = require('discord.js'); | ||
const client = new Discord.Client({ | ||
intents: [ | ||
Discord.GatewayIntentBits.Guilds, | ||
Discord.GatewayIntentBits.GuildMembers, | ||
Discord.GatewayIntentBits.GuildModeration, | ||
Discord.GatewayIntentBits.GuildEmojisAndStickers, | ||
Discord.GatewayIntentBits.GuildWebhooks, | ||
Discord.GatewayIntentBits.GuildInvites, | ||
Discord.GatewayIntentBits.GuildVoiceStates, | ||
Discord.GatewayIntentBits.GuildMessages, | ||
Discord.GatewayIntentBits.DirectMessages, | ||
Discord.GatewayIntentBits.MessageContent, | ||
Discord.GatewayIntentBits.AutoModerationConfiguration, | ||
Discord.GatewayIntentBits.AutoModerationExecution, | ||
] | ||
}); | ||
client.on('ready', async () => { | ||
console.log(`Logged in as ${client.user.tag}!`); | ||
const test = require('../src/functions/tickets/main.js'); | ||
const channel = await client.channels.fetch('1123861563141533754'); | ||
const allMessages = new Discord.Collection(); | ||
let messages = await channel.messages.fetch({ limit: 100, cache: false, | ||
force: true, }); | ||
// //make a simple discord.js client | ||
// const Discord = require('discord.js'); | ||
// const client = new Discord.Client({ | ||
// intents: [ | ||
// Discord.GatewayIntentBits.Guilds, | ||
// Discord.GatewayIntentBits.GuildMembers, | ||
// Discord.GatewayIntentBits.GuildModeration, | ||
// Discord.GatewayIntentBits.GuildEmojisAndStickers, | ||
// Discord.GatewayIntentBits.GuildWebhooks, | ||
// Discord.GatewayIntentBits.GuildInvites, | ||
// Discord.GatewayIntentBits.GuildVoiceStates, | ||
// Discord.GatewayIntentBits.GuildMessages, | ||
// Discord.GatewayIntentBits.DirectMessages, | ||
// Discord.GatewayIntentBits.MessageContent, | ||
// Discord.GatewayIntentBits.AutoModerationConfiguration, | ||
// Discord.GatewayIntentBits.AutoModerationExecution, | ||
// ] | ||
// }); | ||
// client.on('ready', async () => { | ||
// console.log(`Logged in as ${client.user.tag}!`); | ||
// const test = require('../src/functions/tickets/main.js'); | ||
// const channel = await client.channels.fetch('1123861563141533754'); | ||
// const allMessages = new Discord.Collection(); | ||
// let messages = await channel.messages.fetch({ limit: 100, cache: false, | ||
// force: true, }); | ||
|
||
allMessages.concat(messages); | ||
//concat doesnt do anytthing do something else | ||
// console.log(allMessages) | ||
while (messages.size === 100) { | ||
const lastMessageId = messages.lastKey(); | ||
messages = await channel.messages.fetch({ limit: 100, before: lastMessageId, cache: false, | ||
force: true, }); | ||
allMessages.concat(messages); | ||
} | ||
|
||
const trsa = await test.quickExport(channel).catch(console.error); | ||
channel.send({ files: [new Discord.AttachmentBuilder(trsa, { name: `xd.html` })] }) | ||
}); | ||
//login to discord with your app's token | ||
client.login('MTEwOTA2NTQ0MjMwNTI1MzM4Ng.GSKaL5.K6nUopgM92RcZ-_2X6lSUwWcTP_Aa6qtIu324o'); | ||
//when the bot receives a message | ||
// allMessages.concat(messages); | ||
// //concat doesnt do anytthing do something else | ||
// // console.log(allMessages) | ||
// while (messages.size === 100) { | ||
// const lastMessageId = messages.lastKey(); | ||
// messages = await channel.messages.fetch({ limit: 100, before: lastMessageId, cache: false, | ||
// force: true, }); | ||
// allMessages.concat(messages); | ||
// } | ||
|
||
// const trsa = await test.quickExport(channel).catch(console.error); | ||
// channel.send({ files: [new Discord.AttachmentBuilder(trsa, { name: `xd.html` })] }) | ||
// }); | ||
// //login to discord with your app's token | ||
// client.login('MTEwOTA2NTQ0MjMwNTI1MzM4Ng.GSKaL5.K6nUopgM92RcZ-_2X6lSUwWcTP_Aa6qtIu324o'); | ||
// //when the bot receives a message | ||
|
||
const {prettyBytes} = require('../index.js') | ||
console.log(prettyBytes(100000, {locale: 'de'}, {bits: true})) |