summaryrefslogtreecommitdiff
path: root/src/commands/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/server')
-rw-r--r--src/commands/server/oldestmember.ts50
-rw-r--r--src/commands/server/quotemessage.ts88
-rw-r--r--src/commands/server/randommember.ts34
-rw-r--r--src/commands/server/roleinfo.ts61
-rw-r--r--src/commands/server/roles.ts41
5 files changed, 274 insertions, 0 deletions
diff --git a/src/commands/server/oldestmember.ts b/src/commands/server/oldestmember.ts
new file mode 100644
index 0000000..c14e694
--- /dev/null
+++ b/src/commands/server/oldestmember.ts
@@ -0,0 +1,50 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random'
+import { formatDistance, formatRelative } from 'date-fns'
+import { stripIndents } from 'common-tags'
+
+module.exports = class OldestMemberServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'oldestmember',
+ aliases: [
+ 'oldest-member',
+ 'oldestuser',
+ 'oldest-user',
+ 'oldest'
+ ],
+ group: 'fun',
+ memberName: 'oldestmember',
+ description: 'Checks who the oldest member on the server is.',
+ examples: ['uwu!oldestmember'],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ guildOnly: true
+ });
+ }
+ run(msg: CommandoMessage) {
+ const oldest = msg.guild.members
+ .cache.sort((member1, member2) => {
+ const timestamp1 = member1.user.createdTimestamp
+ const timestamp2 = member2.user.createdTimestamp
+
+ if (timestamp1 > timestamp2) {
+ return 1
+ } else if (timestamp1 < timestamp2) {
+ return -1
+ }
+ return 0
+ })
+ .first()?.user
+
+ const { createdAt } = oldest
+ const age = formatDistance(createdAt, new Date())
+ const date = formatRelative(createdAt, new Date())
+ msg.reply(stripIndents`${oldest.tag} is the oldest member in this server.
+ Their account is **${age}** old (created **${date}**).` + ' ' + emoji.random())
+ }
+}; \ No newline at end of file
diff --git a/src/commands/server/quotemessage.ts b/src/commands/server/quotemessage.ts
new file mode 100644
index 0000000..7dc2965
--- /dev/null
+++ b/src/commands/server/quotemessage.ts
@@ -0,0 +1,88 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random'
+import { MessageEmbed } from 'discord.js';
+import tt from '../../utils/truncateText.js'
+import path from 'path'
+
+module.exports = class QuoteMessageServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'quotemessage',
+ aliases: [
+ 'quote-message',
+ 'quotemsg',
+ 'quote-msg'
+ ],
+ group: 'fun',
+ memberName: 'quotemessage',
+ description: 'Quote a message from a text channel.',
+ examples: ['uwu!quotemessage 424936127154094080'],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ args: [
+ {
+ key: 'mMsg',
+ prompt: 'What message would you like to quote?',
+ type: 'message',
+ label: 'message ID'
+ }
+ ]
+ });
+ }
+ run(msg: CommandoMessage, { mMsg }) {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .setTimestamp(mMsg.createdAt)
+ .setAuthor(mMsg.author.tag, mMsg.author.avatarUrl) // TODO: fix avatarurl not working
+ .addFields([
+ {
+ name: 'Channel',
+ value: mMsg.channel.toString()
+ },
+ {
+ name: 'Message',
+ value: `[Jump to](https://discordapp.com/channels/${mMsg.guild.id}/${mMsg.channel.id}/${mMsg.id})`
+ }
+ ])
+
+ // check if msg had content
+ console.debug('Does the message have content:', Boolean(mMsg.content))
+ if (mMsg.content) emb.setDescription(tt(mMsg.content))
+
+ // get img from msg
+ let messageImage
+ // valid img file extensions
+ const extensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp']
+ // regex for url to img
+ const linkRegex = /https?:\/\/(?:\w+\.)?[\w-]+\.[\w]{2,3}(?:\/[\w-_.]+)+\.(?:png|jpg|jpeg|gif|webp)/;
+
+ // embed (that may or may not exist) with an img in it
+ const imageEmbed = mMsg.embeds.find(
+ msgEmbed => msgEmbed.type === 'rich' && msgEmbed.image && extensions.includes(path.extname(msgEmbed.image.url))
+ )
+ if (imageEmbed) messageImage = imageEmbed.image.url
+
+ // uploaded img
+ const attachment = mMsg.attachments.find(file => extensions.includes(path.extname(file.url)))
+ if (attachment) {
+ messageImage = attachment.url
+ }
+
+ // if there wasnt an uploaded img check if there was a url to one
+ if (!messageImage) {
+ const linkMatch = mMsg.content.match(linkRegex)
+ if (linkMatch && extensions.includes(path.extname(linkMatch[0]))) {
+ [messageImage] = linkMatch
+ }
+ }
+
+ // if there was an img, set embed image to it
+ if (messageImage) emb.setImage(messageImage)
+
+ msg.say(emb)
+ }
+}; \ No newline at end of file
diff --git a/src/commands/server/randommember.ts b/src/commands/server/randommember.ts
new file mode 100644
index 0000000..e818e61
--- /dev/null
+++ b/src/commands/server/randommember.ts
@@ -0,0 +1,34 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random'
+
+module.exports = class RandomMemberServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'randommember',
+ aliases: [
+ 'random-member',
+ 'randomuser',
+ 'random-user',
+ 'someone',
+ '@someone',
+ ],
+ group: 'fun',
+ memberName: 'randommember',
+ description: 'Gets a random member from the server.',
+ examples: ['uwu!randommember'],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
+ });
+ }
+ run(msg: CommandoMessage) {
+ if (msg.channel.type === 'dm') {
+ const members = [this.client.user, msg.channel.recipient];
+ return msg.reply(`I choose ${members[Math.floor(Math.random() * members.length)].username}! ${emoji.random()}`);
+ }
+ return msg.reply(`I choose ${msg.guild.members.cache.random().displayName}! ${emoji.random()}`);
+ }
+}; \ No newline at end of file
diff --git a/src/commands/server/roleinfo.ts b/src/commands/server/roleinfo.ts
new file mode 100644
index 0000000..3fc3814
--- /dev/null
+++ b/src/commands/server/roleinfo.ts
@@ -0,0 +1,61 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random'
+import { MessageEmbed } from 'discord.js';
+
+module.exports = class RoleInfoServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'roleinfo',
+ aliases: [
+ 'role-info'
+ ],
+ group: 'fun',
+ memberName: 'roleinfo',
+ description: 'Gets information on a specified role.',
+ examples: ['uwu!roleinfo @Role'],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ guildOnly: true,
+ args: [
+ {
+ key: 'rRole',
+ prompt: 'What role would you like to get information on?',
+ type: 'role'
+ }
+ ]
+ });
+ }
+ run(msg: CommandoMessage, { rRole }) {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .setTitle(`${rRole.name} (${rRole.id})`)
+ .setTimestamp(rRole.createdAt)
+ .addFields([
+ {
+ name: '🔢 Position',
+ value: `${rRole.position + 1} (raw position: ${rRole.rawPosition})`
+ },
+ {
+ name: '**@** Mentionable',
+ value: rRole.mentionable ? 'Yes' : 'No'
+ },
+ {
+ name: "💡 Display separately",
+ value: rRole.hoist ? "Yes" : "No"
+ },
+ {
+ name: "👥 Members",
+ value: rRole.members.size
+ },
+ {
+ name: "🔍 Color",
+ value: `Use ${msg.anyUsage(`color ${rRole.hexColor}`)}`
+ }
+ ])
+ msg.say(emb)
+ }
+}; \ No newline at end of file
diff --git a/src/commands/server/roles.ts b/src/commands/server/roles.ts
new file mode 100644
index 0000000..e55f3a8
--- /dev/null
+++ b/src/commands/server/roles.ts
@@ -0,0 +1,41 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import emoji from 'emoji-random'
+import { MessageEmbed } from 'discord.js';
+import tt from '../../utils/truncateText.js'
+
+module.exports = class RolesServer extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'roles',
+ aliases: [
+ 'list-roles',
+ 'listroles',
+ 'roles-list',
+ 'roleslist'
+ ],
+ group: 'fun',
+ memberName: 'roles',
+ description: 'Lists all the roles on the current server.',
+ examples: ['uwu!roles'],
+ throttling: {
+ usages: 5,
+ duration: 30
+ },
+ userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
+ guildOnly: true
+ });
+ }
+ run(msg: CommandoMessage) {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .setTitle('All Roles')
+ .setDescription(tt(
+ msg.guild.roles
+ .cache.sort((role1, role2) => role2.position - role1.position)
+ .array()
+ .join(', ')
+ ))
+ msg.say(emb)
+ }
+}; \ No newline at end of file