From 7d1adaec39566cd414e5dfff28570e2970f8d4f8 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 30 Aug 2017 22:14:24 +0000 Subject: [PATCH] Remove moment and moment-duration-format --- commands/avatar-edit/card.js | 3 +-- commands/guild-info/channel-info.js | 3 +-- commands/guild-info/role-info.js | 3 +-- commands/guild-info/server-info.js | 3 +-- commands/search/github.js | 5 ++--- commands/search/npm.js | 8 ++++---- commands/search/vocaloid.js | 8 ++++---- commands/search/wattpad.js | 3 +-- commands/user-info/user-info.js | 5 ++--- commands/util/info.js | 5 ++--- commands/util/shard-info.js | 5 ++--- commands/util/uptime.js | 5 ++--- package.json | 4 +--- structures/Util.js | 12 ++++++++++++ 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/commands/avatar-edit/card.js b/commands/avatar-edit/card.js index ff738324..98eea809 100644 --- a/commands/avatar-edit/card.js +++ b/commands/avatar-edit/card.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { createCanvas, loadImage, registerFont } = require('canvas'); const snekfetch = require('snekfetch'); -const moment = require('moment'); const path = require('path'); const { version } = require('../../package'); @@ -56,7 +55,7 @@ module.exports = class CardCommand extends Command { ctx.fillStyle = 'black'; ctx.fillText(member.displayName, 30, 62); ctx.fillText('Discord Join Date:', 148, 400); - ctx.fillText(moment(member.user.createdTimestamp).format('MMMM Do YYYY'), 148, 420); + ctx.fillText(member.user.createdAt.toDateString(), 148, 420); ctx.fillText('Role:', 148, 457); ctx.fillText(member.highestRole.name !== '@everyone' ? member.highestRole.name : 'None', 148, 477); ctx.fillText(rarity, 73, 411); diff --git a/commands/guild-info/channel-info.js b/commands/guild-info/channel-info.js index ac3c651e..a302db8e 100644 --- a/commands/guild-info/channel-info.js +++ b/commands/guild-info/channel-info.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); -const moment = require('moment'); module.exports = class ChannelInfoCommand extends Command { constructor(client) { @@ -34,7 +33,7 @@ module.exports = class ChannelInfoCommand extends Command { .addField('❯ NSFW', channel.nsfw ? 'Yes' : 'No', true) .addField('❯ Creation Date', - moment(channel.createdAt).format('MMMM Do YYYY'), true) + channel.createdAt.toDateString(), true) .addField('❯ Topic', channel.topic || 'None'); return msg.embed(embed); diff --git a/commands/guild-info/role-info.js b/commands/guild-info/role-info.js index b946c1ee..17a9517f 100644 --- a/commands/guild-info/role-info.js +++ b/commands/guild-info/role-info.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); -const moment = require('moment'); const perms = require('../../assets/json/permissions'); module.exports = class RoleInfoCommand extends Command { @@ -34,7 +33,7 @@ module.exports = class RoleInfoCommand extends Command { .addField('❯ Color', role.hexColor.toUpperCase(), true) .addField('❯ Creation Date', - moment(role.createdAt).format('MMMM Do YYYY'), true) + role.createdAt.toDateString(), true) .addField('❯ Hoisted', role.hoist ? 'Yes' : 'No', true) .addField('❯ Mentionable', diff --git a/commands/guild-info/server-info.js b/commands/guild-info/server-info.js index 9699eb2d..7a87fefb 100644 --- a/commands/guild-info/server-info.js +++ b/commands/guild-info/server-info.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); -const moment = require('moment'); const filterLevels = ['Off', 'No Role', 'Everyone']; const verificationLevels = ['None', 'Low', 'Medium', '(╯°□°)╯︵ ┻━┻', '┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻']; @@ -26,7 +25,7 @@ module.exports = class GuildInfoCommand extends Command { .addField('❯ ID', msg.guild.id, true) .addField('❯ Creation Date', - moment(msg.guild.createdAt).format('MMMM Do YYYY'), true) + msg.guild.createdAt.toDateString(), true) .addField('❯ Region', msg.guild.region, true) .addField('❯ Explicit Filter', diff --git a/commands/search/github.js b/commands/search/github.js index 4889aef1..fce813eb 100644 --- a/commands/search/github.js +++ b/commands/search/github.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const moment = require('moment'); const { GITHUB_LOGIN } = process.env; module.exports = class GitHubCommand extends Command { @@ -48,9 +47,9 @@ module.exports = class GitHubCommand extends Command { .addField('❯ Language', body.language || 'N/A', true) .addField('❯ Created', - moment(body.created_at).format('MMMM Do YYYY'), true) + new Date(body.created_at).toDateString(), true) .addField('❯ Modified', - moment(body.updated_at).format('MMMM Do YYYY'), true); + new Date(body.updated_at).toDateString(), true); return msg.embed(embed); } catch (err) { if (err.status === 404) return msg.say('Could not find any results.'); diff --git a/commands/search/npm.js b/commands/search/npm.js index 30d7e0d2..4632b25d 100644 --- a/commands/search/npm.js +++ b/commands/search/npm.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const moment = require('moment'); const { shorten } = require('../../structures/Util'); module.exports = class NPMCommand extends Command { @@ -16,7 +15,8 @@ module.exports = class NPMCommand extends Command { { key: 'query', prompt: 'What package would you like to search for?', - type: 'string' + type: 'string', + parse: query => encodeURIComponent(query) } ] }); @@ -40,9 +40,9 @@ module.exports = class NPMCommand extends Command { .addField('❯ Author', body.author ? body.author.name : 'Unknown', true) .addField('❯ Created', - moment(body.time.created).format('MMMM Do YYYY'), true) + new Date(body.time.created).toDateString(), true) .addField('❯ Modified', - moment(body.time.modified).format('MMMM Do YYYY'), true) + new Date(body.time.modified).toDateString(), true) .addField('❯ Main File', body.versions[body['dist-tags'].latest].main, true) .addField('❯ Keywords', diff --git a/commands/search/vocaloid.js b/commands/search/vocaloid.js index 0cf386d5..7902e9be 100644 --- a/commands/search/vocaloid.js +++ b/commands/search/vocaloid.js @@ -1,8 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const moment = require('moment'); -const { shorten } = require('../../structures/Util'); +const { shorten, duration } = require('../../structures/Util'); module.exports = class VocaloidCommand extends Command { constructor(client) { @@ -37,6 +36,7 @@ module.exports = class VocaloidCommand extends Command { fields: 'ThumbUrl,Lyrics' }); if (!body.totalCount) return msg.say('Could not find any results.'); + const { minutes, seconds } = duration(body.items[0].lengthSeconds * 1000); const embed = new MessageEmbed() .setColor(0x86D2D0) .setAuthor('VocaDB', 'https://i.imgur.com/9Tx9UIc.jpg') @@ -47,9 +47,9 @@ module.exports = class VocaloidCommand extends Command { .addField('❯ Artist', body.items[0].artistString) .addField('❯ Publish Date', - moment(body.items[0].publishDate).format('MMMM Do YYYY'), true) + new Date(body.items[0].publishDate).toDateString(), true) .addField('❯ Length', - moment.duration(body.items[0].lengthSeconds, 's').format(), true); + `${minutes}:${seconds}`, true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index b7336449..5d2141cc 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -const moment = require('moment'); const { shorten } = require('../../structures/Util'); const { WATTPAD_KEY } = process.env; @@ -42,7 +41,7 @@ module.exports = class WattpadCommand extends Command { .setDescription(shorten(body.stories[0].description)) .setThumbnail(body.stories[0].cover) .addField('❯ Created On', - moment(body.stories[0].createDate).format('MMMM Do YYYY'), true) + new Date(body.stories[0].createDate).toDateString(), true) .addField('❯ Author', body.stories[0].user, true) .addField('❯ Parts', diff --git a/commands/user-info/user-info.js b/commands/user-info/user-info.js index 9bd1868e..ad58a58f 100644 --- a/commands/user-info/user-info.js +++ b/commands/user-info/user-info.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); -const moment = require('moment'); const statuses = { online: '<:online:313956277808005120> Online', idle: '<:away:313956277220802560> Idle', @@ -39,9 +38,9 @@ module.exports = class UserInfoCommand extends Command { .addField('❯ ID', member.id, true) .addField('❯ Discord Join Date', - moment(member.user.createdAt).format('MMMM Do YYYY'), true) + member.user.createdAt.toDateString(), true) .addField('❯ Server Join Date', - moment(member.joinedTimestamp).format('MMMM Do YYYY'), true) + member.joinedAt.toDateString(), true) .addField('❯ Status', statuses[member.presence.status], true) .addField('❯ Playing', diff --git a/commands/util/info.js b/commands/util/info.js index f7f29fe0..4dcbe15f 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -1,8 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { version } = require('../../package'); -const moment = require('moment'); -require('moment-duration-format'); +const { duration } = require('../../structures/Util'); module.exports = class InfoCommand extends Command { constructor(client) { @@ -34,7 +33,7 @@ module.exports = class InfoCommand extends Command { .addField('❯ Memory Usage', `${Math.round(memory.reduce((prev, val) => prev + val, 0) / 1024 / 1024)}MB`, true) .addField('❯ Uptime', - moment.duration(this.client.uptime).format('d[d]h[h]m[m]s[s]'), true) + duration(this.client.uptime).format, true) .addField('❯ Version', `v${version}`, true) .addField('❯ Node Version', diff --git a/commands/util/shard-info.js b/commands/util/shard-info.js index f452d219..65d8f65b 100644 --- a/commands/util/shard-info.js +++ b/commands/util/shard-info.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); -const moment = require('moment'); -require('moment-duration-format'); +const { duration } = require('../../structures/Util'); module.exports = class ShardInfoCommand extends Command { constructor(client) { @@ -40,7 +39,7 @@ module.exports = class ShardInfoCommand extends Command { .addField('❯ Memory Usage', `${Math.round(memory[shard] / 1024 / 1024)}MB`, true) .addField('❯ Uptime', - moment.duration(uptime[shard]).format('d[d]h[h]m[m]s[s]'), true); + duration(uptime[shard]).format, true); return msg.embed(embed); } }; diff --git a/commands/util/uptime.js b/commands/util/uptime.js index 9f15d965..b524eaa6 100644 --- a/commands/util/uptime.js +++ b/commands/util/uptime.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); -const moment = require('moment'); -require('moment-duration-format'); +const { duration } = require('../../structures/Util'); module.exports = class UptimeCommand extends Command { constructor(client) { @@ -14,6 +13,6 @@ module.exports = class UptimeCommand extends Command { } run(msg) { - return msg.say(moment.duration(this.client.uptime).format('d[ days], h[ hours], m[ minutes, and ]s[ seconds]')); + return msg.say(duration(this.client.uptime).format); } }; diff --git a/package.json b/package.json index 24f714f2..90c158f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "34.0.1", + "version": "34.0.2", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -36,8 +36,6 @@ "discord.js": "github:hydrabolt/discord.js", "discord.js-commando": "github:gawdl3y/discord.js-commando", "erlpack": "github:hammerandchisel/erlpack", - "moment": "^2.18.1", - "moment-duration-format": "^1.3.0", "node-opus": "^0.2.6", "snekfetch": "^3.2.9", "uws": "^8.14.1", diff --git a/structures/Util.js b/structures/Util.js index efd7820b..95053133 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -73,6 +73,18 @@ class Util { const filtered = arr.filter(entry => entry.language.name === 'en'); return filtered[Math.floor(Math.random() * filtered.length)]; } + + static duration(ms) { + const sec = Math.floor((ms / 1000) % 60); + const min = Math.floor((ms / (1000 * 60)) % 60); + const hrs = Math.floor(ms / (1000 * 60 * 60)); + return { + hours: hrs, + minutes: min, + seconds: sec, + format: `${hrs < 10 ? `0${hrs}` : hrs}:${min < 10 ? `0${min}` : min}:${sec < 10 ? `0${sec}` : sec}` + }; + } } module.exports = Util;