Skip to content

Commit

Permalink
Merge pull request #161 from iminlikewithyou/bloxlink
Browse files Browse the repository at this point in the history
Add commands for Bloxlink integration
  • Loading branch information
iminlikewithyou authored Jul 7, 2024
2 parents 7330afb + e06d2ee commit 8d9eebe
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 13 deletions.
13 changes: 13 additions & 0 deletions lame-bot/commands/bloxlink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { replyToInteraction } from "../../src/command-handler";

export const data = new SlashCommandBuilder()
.setName("bloxlink")
.setDescription("Connect your Roblox account to Discord using Bloxlink!");

export const cooldown = 10 * 1000;
export const broadcastable = true;

export async function execute(interaction: ChatInputCommandInteraction, preferBroadcast: boolean) {
await replyToInteraction(interaction, "Verify", "\n• Connect your Roblox account to Discord using Bloxlink [using this link](https://blox.link/dashboard/user/verifications/verify).", preferBroadcast);
}
6 changes: 3 additions & 3 deletions lame-bot/commands/duel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function execute(interaction: CommandInteraction, preferBroadcast:
let gameName = interaction.options.get("game")?.name ?? "Word Bomb";

if (user === interaction.user) {
replyToInteraction(interaction, "Duel", "\n• You can't duel yourself!", false);
await replyToInteraction(interaction, "Duel", "\n• You can't duel yourself!", false);
return;
}

Expand All @@ -66,9 +66,9 @@ export async function execute(interaction: CommandInteraction, preferBroadcast:
);
} catch (err) {
console.error(err);
replyToInteraction(interaction, "Duel", "\n• Sorry, I couldn't send a DM to that user!", false);
await replyToInteraction(interaction, "Duel", "\n• Sorry, I couldn't send a DM to that user!", false);
return;
}

replyToInteraction(interaction, "Duel", "\n• Sent a duel request to <@" + user.id + ">!\nClick to join the [reserved server](" + link + ").", false);
await replyToInteraction(interaction, "Duel", "\n• Sent a duel request to <@" + user.id + ">!\nClick to join the [reserved server](" + link + ").", false);
}
62 changes: 62 additions & 0 deletions lame-bot/commands/roblox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
import { replyToInteraction } from "../../src/command-handler";
import { escapeDiscordMarkdown } from "../../src/utils";

export const data = new SlashCommandBuilder()
.setName("roblox")
.setDescription("View a user's Roblox profile!")
.addUserOption(option =>
option.setName("user")
.setDescription("The user to view the profile of")
.setRequired(false));

export const cooldown = 10 * 1000;
export const broadcastable = true;

export async function execute(interaction: ChatInputCommandInteraction, preferBroadcast: boolean) {
const userID = interaction.options.getUser("user")?.id ?? interaction.user.id;
try {
const result = await fetch(`https://api.blox.link/v4/public/guilds/476593983485902850/discord-to-roblox/${userID}`, { headers: { "Authorization": process.env.BLOXLINK_KEY } });
const data = await result.json();
if (data.error) {
const errorMessage = data.error.endsWith(".") ? data.error : data.error + ".";
await replyToInteraction(interaction, "Profile", "\n• " + escapeDiscordMarkdown(errorMessage), preferBroadcast);
return;
}

const robloxInformation = data.resolved.roblox;

const robloxName = robloxInformation.displayName ?? robloxInformation.name;
const robloxUsername = robloxInformation.name;
const robloxLink = robloxInformation.profileLink;
const robloxDescription = robloxInformation.description;

// oh my goodness
let robloxImage = null;
if (robloxInformation.avatar) {
if (robloxInformation.avatar.fullBody) {
const imageData = await (await fetch(robloxInformation.avatar.fullBody)).json();
if (imageData.data && imageData.data[0] && imageData.data[0].imageUrl) {
robloxImage = imageData.data[0].imageUrl;
}
}
}

const text = `<@${userID}> is **${robloxName}** on Roblox.`;
const embed = new EmbedBuilder()
.setAuthor({ name: "@" + robloxUsername })
.setTitle(robloxName)
.setURL(robloxLink)
.setDescription(robloxDescription)
.setThumbnail(robloxImage)
.setColor("#00a8ff");

await replyToInteraction(interaction, "Profile", "\n" + text + "\n** **", preferBroadcast, {
allowedMentions: { parse: [] },
embeds: [embed]
});
} catch (error) {
console.error(error);
await replyToInteraction(interaction, "Profile", "\n• An error occurred while fetching the profile.", false);
}
}
12 changes: 6 additions & 6 deletions lame-bot/commands/setboosterbadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export async function execute(interaction: CommandInteraction, _preferBroadcast:
if (interaction.guild.premiumTier < 2) {
// this is mainly to prevent people from using this while the server doesnt have
// the correct boost level and casuing a ton of errors
replyToInteraction(interaction, "Error", "\nYou can't use booster roles yet, the server must be at least level 2!", false);
await replyToInteraction(interaction, "Error", "\nYou can't use booster roles yet, the server must be at least level 2!", false);
return;
}

if (!isBooster(userRoles)) {
replyToInteraction(interaction, "Error", "\nYou must be a booster to use this command.", false);
await replyToInteraction(interaction, "Error", "\nYou must be a booster to use this command.", false);
return;
}

Expand All @@ -63,7 +63,7 @@ export async function execute(interaction: CommandInteraction, _preferBroadcast:
case "image/webp":
break;
default:
replyToInteraction(interaction, "Error", "\nPlease use a valid image type.", false);
await replyToInteraction(interaction, "Error", "\nPlease use a valid image type.", false);
return;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export async function execute(interaction: CommandInteraction, _preferBroadcast:
setBoosterRole(interaction.user.id, userBoosterRole.id);
} catch (e) {
console.error(e);
replyToInteraction(interaction, "Error", `\nFailed to create your role!\nTry again later.`, false);
await replyToInteraction(interaction, "Error", `\nFailed to create your role!\nTry again later.`, false);
return;
}
}
Expand All @@ -112,10 +112,10 @@ export async function execute(interaction: CommandInteraction, _preferBroadcast:
await assignRole(interaction.user.id, userBoosterRole.id);
} catch (e) {
console.error(e);
replyToInteraction(interaction, "Error", `\nFailed to add you to the role!\nTry again later.`, false);
await replyToInteraction(interaction, "Error", `\nFailed to add you to the role!\nTry again later.`, false);
return;
}
}

replyToInteraction(interaction, "Booster Badge", "\nSuccessfully set your booster badge!", false);
await replyToInteraction(interaction, "Booster Badge", "\nSuccessfully set your booster badge!", false);
}
9 changes: 7 additions & 2 deletions src/command-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { REST } from "@discordjs/rest";
import { ChannelType, Client, Collection, CommandInteraction, Events, GuildMember, GuildTextBasedChannel, Message, Routes } from "discord.js";
import { ChannelType, Client, Collection, CommandInteraction, Events, GuildMember, GuildTextBasedChannel, InteractionReplyOptions, Message, MessageMentionOptions, Routes } from "discord.js";
import fs from "node:fs";
import { escapeDiscordMarkdown } from "./utils";

Expand Down Expand Up @@ -382,10 +382,15 @@ export function getInteractionContent(interaction: CommandInteraction, header: s
* @param response The response text.
* @param broadcast Whether or not this interaction is being broadcasted.
*/
export async function replyToInteraction(interaction: CommandInteraction, header: string, response: string, broadcast: boolean) {
export async function replyToInteraction(interaction: CommandInteraction, header: string, response: string, broadcast: boolean, options?: Partial<InteractionReplyOptions>) {
if (interaction.replied) {
return;
}

await interaction.reply({
content: getInteractionContent(interaction, header, response, broadcast),
ephemeral: !broadcast,
...options
});
}

Expand Down
4 changes: 2 additions & 2 deletions vivi/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function versionCommand(interaction, broadcastThis) {
async function versionCommand(interaction, broadcastThis) {
// TODO: Finish the file
// @ts-ignore
replyToInteraction(interaction, "Version", "\n• v" + version, broadcastThis);
await replyToInteraction(interaction, "Version", "\n• v" + version, broadcastThis);
}

0 comments on commit 8d9eebe

Please sign in to comment.