Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
✨ Select VC and connect
Browse files Browse the repository at this point in the history
  • Loading branch information
suzukey committed Oct 16, 2020
1 parent 133d335 commit 8df7cc6
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 5 deletions.
38 changes: 38 additions & 0 deletions config/emojis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
"\ud83c\udde6",
"\ud83c\udde7",
"\ud83c\udde8",
"\ud83c\udde9",
"\ud83c\uddea",
"\ud83c\uddeb",
"\ud83c\uddec",
"\ud83c\udded",
"\ud83c\uddee",
"\ud83c\uddef",
"\ud83c\uddf0",
"\ud83c\uddf1",
"\ud83c\uddf2",
"\ud83c\uddf3",
"\ud83c\uddf4",
"\ud83c\uddf5",
"\ud83c\uddf6",
"\ud83c\uddf7",
"\ud83c\uddf8",
"\ud83c\uddf9",
"\ud83c\uddfa",
"\ud83c\uddfb",
"\ud83c\uddfc",
"\ud83c\uddfd",
"\ud83c\uddfe",
"\ud83c\uddff",
"1\ufe0f\u20e3",
"2\ufe0f\u20e3",
"3\ufe0f\u20e3",
"4\ufe0f\u20e3",
"5\ufe0f\u20e3",
"6\ufe0f\u20e3",
"7\ufe0f\u20e3",
"8\ufe0f\u20e3",
"9\ufe0f\u20e3",
"10\ufe0f\u20e3"
]
116 changes: 111 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,121 @@ if (Number(process.version.slice(1).split(".")[0]) < 12)
const discord = require("discord.js")

const secrets = require("./config/secrets.json")
const config = require("./config/settings.json")

const transfer_bots = {
const clients = {
from: new discord.Client(),
to: new discord.Client()
}

const init = async () => {
transfer_bots.from.login(secrets.from_token)
transfer_bots.to.login(secrets.to_token)
const login = async () => {
clients.from.login(secrets.from_token)
clients.to.login(secrets.to_token)
}

init()
clients.from.once("ready", () => {
console.log(`transfer_from: ${clients.from.user.tag} on ready`)
clients.from.voice
})

clients.to.once("ready", () => {
console.log(`transfer_to: ${clients.to.user.tag} on ready`)
})

clients.from.on("message", async (message) => {
if (message.content.indexOf(config.prefix) !== 0) return

const command_extraction = message.content.slice(config.prefix.length).trim()
const args = command_extraction.split(/ +/g)
const command = args.shift().toLowerCase()

if (command === "trans" || command === "transfer") {
message.delete()

const channels = message.guild.channels.cache.array()
const voice_channels = channels.filter((channel) => channel.type === "voice")

if (voice_channels.length < 2) {
message.channel.send("error: Requires at least two voice channels")
return
}

let remain_vc = voice_channels
const from_ch = await question_channels(message, remain_vc, "Voice transfer to")
if (!from_ch) return

remain_vc = remain_vc.filter((channel) => channel !== from_ch)
const to_ch = await question_channels(message, remain_vc, "Voice transfer to")
if (!to_ch) return

// Assign a channel to each client
const conn_from = await clients.from.channels.cache.get(from_ch.id).join()
const conn_to = await clients.to.channels.cache.get(to_ch.id).join()
}
})

const question_channels = async (message, channels, question_desc) => {
const emojis = require("./config/emojis.json")

const ch_count = channels.length

if (emojis.length < ch_count) {
message.channel.send("error: Too many voice channels")
return
}

// Prepare as many emoji as their channels
const ch_emojis = emojis.slice(0, ch_count)
let question = {
embed: {
color: 0xe2b618,
title: "Select Channel",
description: question_desc,
fields: []
}
}

for (let i = 0; i < ch_count; i++) {
const field = {
name: ch_emojis[i],
value: channels[i].name
}
question.embed.fields.push(field)
}

const reaction = await question_react(message, ch_emojis, question)
if (!reaction) return

const selected_channel = channels[emojis.indexOf(reaction)]
return selected_channel
}

// Ask a question and wait for a reaction
const question_react = async (message, emojis, question) => {
const question_msg = await message.channel.send("wait...")
const wait_reaction_setting = await question_msg.react("⏳")

await Promise.all(
emojis.map((emoji) => {
question_msg.react(emoji)
})
)

await wait_reaction_setting.remove()
await question_msg.edit(question)

const filter = (reaction, user) => {
if (user.id !== message.author.id) return false
return emojis.includes(reaction.emoji.name)
}

const answer_reaction = await question_msg.awaitReactions(filter, {
max: 1,
time: 10000
})
await question_msg.delete()

if (answer_reaction.size) return answer_reaction.first()._emoji.name
}

login()

0 comments on commit 8df7cc6

Please sign in to comment.