Skip to content

Commit

Permalink
Merge pull request #6 from jmhayes3/feature/command-embeddings
Browse files Browse the repository at this point in the history
use embeddings in command replies
  • Loading branch information
jmhayes3 authored Aug 24, 2024
2 parents bd0dfc7 + a83dde1 commit 5f01024
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 36 deletions.
22 changes: 22 additions & 0 deletions cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Keyv from 'keyv';
import KeyvRedis from '@keyv/redis';

const keyvRedis = new KeyvRedis('redis://127.0.0.1:6379');
console.log(keyvRedis);

const cache = new Keyv({ store: keyvRedis, namespace: 'cache' });
console.log(cache);

const users = new Keyv(new KeyvRedis('redis://localhost:6379'), { namespace: 'users' });
console.log(users);

await users.set("foo", "bar");
console.log(await users.get('foo'));

await cache.set('testing', false);
await cache.set('foo', 'foobar');
await cache.set('bar', 'barfoo');
console.log(await cache.get('testing'));
console.log(await cache.get('foo'));
console.log(await cache.get('bar'));
await cache.clear();
14 changes: 0 additions & 14 deletions commands/core/profile.js

This file was deleted.

38 changes: 38 additions & 0 deletions commands/core/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';

export const data = new SlashCommandBuilder().setName('role').setDescription('Display role info').addRoleOption(option => option.setName('role').setDescription("The role you want to get the info of").setRequired(true));

export async function execute(interaction) {
const { options } = interaction;

const role = options.getRole('role');

if (!role || !role.id) return interaction.reply({ content: `That role **doesn't** seem to exist in ${interaction.guild.name}`, ephemeral: true });
if (role.name === "@everyone") return interaction.reply({ content: `You **cannot** get the info of the \`\`@everyone\`\``, ephemeral: true });
if (role.name === "@here") return interaction.reply({ content: `You **cannot** get the info of the \`\`@here\`\``, ephemeral: true });

const created = parseInt(role.createdTimestamp / 1000);
const isMentionable = role.isMentionable ? "true" : "false";
const isManaged = role.isManaged ? "true" : "false";
const isHigher = role.isHigher ? "true" : "false";
const position = role.position;
const isBotRole = role.isBotRole ? "true" : "false";

const roleEmbed = new EmbedBuilder()
.setColor(role.color)
.setTitle("Role info")
.addFields(
{ name: "Name", value: `> ${role.name}` },
{ name: "Color", value: `> ${role.hexColor}` },
{ name: "Mention", value: `> @${role.name}` },
{ name: "Hoisted", value: `> ${isHigher}` },
{ name: "Position", value: `> ${position}` },
{ name: "Mentionable", value: `> ${isMentionable}` },
{ name: "Managed", value: `> ${isManaged}` },
{ name: "Bot", value: `> ${isBotRole}` },
{ name: "Created", value: `> <t:${created}:R>` })
.setFooter({ text: `Role ID: ${role.id}` })
.setThumbnail(role.iconURL());

await interaction.reply({ embeds: [roleEmbed], ephemeral: true })
}
27 changes: 27 additions & 0 deletions commands/core/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';

export const data = new SlashCommandBuilder().setName('server').setDescription('Display server info');

export async function execute(interaction) {
if (!interaction.isChatInputCommand()) return;

await interaction.deferReply({ ephemeral: true });

const server = interaction.guild;
const members = interaction.guild.memberCount;
const created = parseInt(interaction.guild.createdTimestamp / 1000);

const serverEmbed = new EmbedBuilder()
.setColor('#777777')
.setTitle("Server info")
.addFields(
{ name: "Name", value: `> ${server.name}` },
{ name: "Members", value: `> ${members}` },
{ name: "Owner ID", value: `> ${server.ownerId}` },
{ name: "Created", value: `> <t:${created}:R>` })
.setFooter({ text: `Server ID: ${server.id}` })
.setThumbnail(server.iconURL())

const reply = { embeds: [serverEmbed], ephemeral: true };
await interaction.followUp(reply);
};
26 changes: 26 additions & 0 deletions commands/core/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';

export const data = new SlashCommandBuilder().setName('user').setDescription('Display user info');

export async function execute(interaction) {
if (!interaction.isChatInputCommand()) return;

await interaction.deferReply({ ephemeral: true });

const user = interaction.user;
const created = parseInt(interaction.user.createdTimestamp / 1000);

const userEmbed = new EmbedBuilder()
.setColor('#195ece')
.setTitle("User info")
.addFields(
{ name: "Username", value: `> ${user.username}` },
{ name: "Joined", value: `> <t:${created}:R>` })
.setFooter({ text: `User ID: ${user.id}` })
.setThumbnail(user.displayAvatarURL());

const reply = { embeds: [userEmbed], ephemeral: true };
console.log(reply);

await interaction.followUp(reply);
};
26 changes: 26 additions & 0 deletions commands/core/userContextMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ContextMenuCommandBuilder, ApplicationCommandType, EmbedBuilder } from 'discord.js';

export const data = new ContextMenuCommandBuilder().setName('User Info').setType(ApplicationCommandType.User);

export async function execute(interaction) {
if (!interaction.isUserContextMenuCommand()) return;

await interaction.deferReply({ ephemeral: true });

const user = interaction.user;
const created = parseInt(interaction.user.createdTimestamp / 1000);

const userContextMenuEmbed = new EmbedBuilder()
.setColor('#195ece')
.setTitle("User info")
.addFields(
{ name: "Username", value: `> ${user.username}` },
{ name: "Joined", value: `> <t:${created}:R>` })
.setFooter({ text: `User ID: ${user.id}` })
.setThumbnail(user.displayAvatarURL());

const reply = { embeds: [userContextMenuEmbed], ephemeral: true };
console.log(reply);

await interaction.followUp(reply);
};
14 changes: 0 additions & 14 deletions commands/core/who.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for (const folder of commandFolders) {

client.once(Events.ClientReady, () => {
console.log(`Ready! Logged in as ${client.user.tag}`);
client.user.setPresence({ activities: [], status: 'invisible' });
client.user.setPresence({ activities: [], status: 'online' });
});

client.on(Events.InteractionCreate, async (interaction) => {
Expand Down
Loading

0 comments on commit 5f01024

Please sign in to comment.