Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use embeddings in command replies #6

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading