Skip to content

Instantly share code, notes, and snippets.

@quacksire
Created December 20, 2022 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quacksire/27cf04d71db666b3da7f9a9fd325ab0f to your computer and use it in GitHub Desktop.
Save quacksire/27cf04d71db666b3da7f9a9fd325ab0f to your computer and use it in GitHub Desktop.
connect commands (needs to be guild specific)
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder} = require('discord.js');
const firebase = require('../firebase.js');
const {getFirestore} = require("firebase-admin/firestore");
const {getDatabase} = require("firebase-admin/database");
module.exports = {
data: new SlashCommandBuilder()
.setName('info')
.setDescription('Get specifc information about a user.')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to get information about.')
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),
async execute(interaction) {
const app = firebase.app;
const firestore = getFirestore(app)
await interaction.deferReply();
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
let user = interaction.options.getUser('user').id;
const userRelatRef = firestore.collection(`user-relations`).doc("discord").get()
const userRelat = (await userRelatRef).data()
if (!userRelat[user]) {
await interaction.editReply(`<@${user}> has not linked their account to Cider Connect`, { ephemeral: true });
return;
}
let userobj = firestore.doc(`users/${userRelat[user]}`)
let userobjdata = (await userobj.get()).data()
console.log(userobjdata)
let discord = (await firestore.doc(`users/${userRelat[user]}/accounts/discord`).get()).data()
let lastfm = (await firestore.doc(`users/${userRelat[user]}/accounts/lastfm`).get()).data()
let spotify = (await firestore.doc(`users/${userRelat[user]}/accounts/spotify`).get()).data()
let accountCollection = [
{name: "Discord", value: discord ? `<@${discord.id}>` : "Not linked"},
{name: "Last.fm", value: lastfm ? `${lastfm.name}` : "Not linked"},
{name: "Spotify", value: spotify ? `${spotify.username}` : "Not linked"}
]
const exampleEmbed = new EmbedBuilder()
.setTitle(`Information about <@${user}>`)
.setDescription(`
Email: ${userobjdata.email}\n
Listen Together Link: ${userobjdata.link || "Not Set"}\n
Stripe ID: ${userobjdata.stripeId || "Not Set"}\n
Stripe Dashboard Link: ${userobjdata.stripeLink || "Not Set"}\n
`)
.setTimestamp()
.setFooter({ text: `UID: ${userRelat[user]}`});
exampleEmbed.data.fields = accountCollection
await interaction.editReply({ embeds: [exampleEmbed] });
}
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const firebase = require('../firebase.js');
const {getFirestore} = require("firebase-admin/firestore");
const {getDatabase} = require("firebase-admin/database");
module.exports = {
data: new SlashCommandBuilder()
.setName('relay')
.setDescription('Sends a relay command to the specified user.')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to send the relay command to.')
.setRequired(true))
.addStringOption(option =>
option.setName('command')
.setDescription('The command to send to the user.')
.setRequired(true)
.addChoices(
{ name: 'Reload', value: 'reload' },
{ name: 'Listen Together Join (requires `id` arg)', value: 'ltgh' },
{ name: 'Route (requires `page` arg)', value: 'route' },
{ name: 'Open (requires `url` arg)', value: 'open' },
))
.addStringOption(option =>
option.setName('args')
.setDescription('Separate arguments with a comma and a space. (arg1: value1, arg2: value2, etc.)')
.setRequired(false))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
const app = firebase.app;
const firestore = getFirestore(app)
const database = getDatabase(app)
let command = interaction.options.getString('command');
let args = interaction.options.getString('args');
let user = interaction.options.getUser('user').id;
await interaction.deferReply();
// get user mention option id
const userRelatRef = firestore.collection(`user-relations`).doc("discord").get()
const userRelat = (await userRelatRef).data()
if (!userRelat[user]) {
await interaction.editReply(`<@${user}> has not linked their account to Cider Connect`, { ephemeral: true });
return;
}
let uid = userRelat[user];
let data;
if (args) {
args = args.split(', ');
let argsObj = {};
args.forEach((arg) => {
let argSplit = arg.split(': ');
argsObj[argSplit[0]] = argSplit[1];
});
data = {
command: command,
...argsObj
}
} else {
data = {
command: command
}
}
await database.ref(`users/${uid}/relay`).set(data);
await interaction.editReply(`Sent relay command to <@${user}>`, { ephemeral: true });
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const firebase = require('../firebase.js');
const {getFirestore} = require("firebase-admin/firestore");
const {getDatabase} = require("firebase-admin/database");
module.exports = {
data: new SlashCommandBuilder()
.setName('updaterelationships')
.setDescription('Gets all users from the database and updates the user relations.')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),
async execute(interaction) {
const app = firebase.app;
const firestore = getFirestore(app)
await interaction.deferReply();
let users = await firestore.collection('users').get()
let size = 0;
await users.forEach(async (mdoc, i) => {
size++;
await mdoc.ref.listCollections().then(async (collections) => {
await collections.forEach(async (collection) => {
await collection.get().then(async (snapshot) => {
await snapshot.forEach(async (doc) => {
/**
* There is a doc for each account that the user has linked.
*/
const data = doc.data()
if (data.id) { // Discord?
await firestore.collection("user-relations").doc("discord").set({
[data.id]: `${mdoc.id}`
}, { merge: true })
}
})
})
})
})
})
await interaction.editReply(`Synced ${size} user relationships.`);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment