mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-12 21:05:29 +01:00
Merge pull request #330 from luisfavila/join-user-voice-channel
This commit is contained in:
commit
81bbdb971d
|
@ -4,7 +4,7 @@ import {TYPES} from '../types';
|
|||
import {inject, injectable} from 'inversify';
|
||||
import {QueuedSong, STATUS} from '../services/player';
|
||||
import PlayerManager from '../managers/player';
|
||||
import {getMostPopularVoiceChannel} from '../utils/channels';
|
||||
import {getMostPopularVoiceChannel, getMemberVoiceChannel} from '../utils/channels';
|
||||
import LoadingMessage from '../utils/loading-message';
|
||||
import errorMsg from '../utils/error-msg';
|
||||
import Command from '.';
|
||||
|
@ -36,8 +36,8 @@ export default class implements Command {
|
|||
this.getSongs = getSongs;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, args: string []): Promise<void> {
|
||||
const [targetVoiceChannel] = getMostPopularVoiceChannel(msg.guild!);
|
||||
public async execute(msg: Message, args: string[]): Promise<void> {
|
||||
const [targetVoiceChannel] = getMemberVoiceChannel(msg.member!) ?? getMostPopularVoiceChannel(msg.guild!);
|
||||
|
||||
const res = new LoadingMessage(msg.channel as TextChannel);
|
||||
await res.start();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {inject, injectable} from 'inversify';
|
||||
import {Message, Guild} from 'discord.js';
|
||||
import {Message, Guild, GuildMember} from 'discord.js';
|
||||
import {TYPES} from '../types';
|
||||
import PlayerManager from '../managers/player';
|
||||
import {QueuedSong} from '../services/player';
|
||||
import {getMostPopularVoiceChannel} from '../utils/channels';
|
||||
import {getMostPopularVoiceChannel, getMemberVoiceChannel} from '../utils/channels';
|
||||
|
||||
@injectable()
|
||||
export default class {
|
||||
|
@ -24,7 +24,7 @@ export default class {
|
|||
if (msg.content.toLowerCase().includes('packers')) {
|
||||
await Promise.all([
|
||||
msg.channel.send('GO PACKERS GO!!!'),
|
||||
this.playClip(msg.guild!, {title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false}, 8, 10)
|
||||
this.playClip(msg.guild!, msg.member!, {title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false}, 8, 10)
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -33,7 +33,7 @@ export default class {
|
|||
if (msg.content.toLowerCase().includes('bears')) {
|
||||
await Promise.all([
|
||||
msg.channel.send('F*** THE BEARS'),
|
||||
this.playClip(msg.guild!, {title: 'GO PACKERS!', artist: 'Charlie Berens', url: 'https://www.youtube.com/watch?v=UaqlE9Pyy_Q', length: 385, playlist: null, isLive: false}, 358, 5.5)
|
||||
this.playClip(msg.guild!, msg.member!, {title: 'GO PACKERS!', artist: 'Charlie Berens', url: 'https://www.youtube.com/watch?v=UaqlE9Pyy_Q', length: 385, playlist: null, isLive: false}, 358, 5.5)
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -42,7 +42,7 @@ export default class {
|
|||
if (msg.content.toLowerCase().includes('bitconnect')) {
|
||||
await Promise.all([
|
||||
msg.channel.send('🌊 🌊 🌊 🌊'),
|
||||
this.playClip(msg.guild!, {title: 'BITCONNEEECCT', artist: 'Carlos Matos', url: 'https://www.youtube.com/watch?v=lCcwn6bGUtU', length: 227, playlist: null, isLive: false}, 50, 13)
|
||||
this.playClip(msg.guild!, msg.member!, {title: 'BITCONNEEECCT', artist: 'Carlos Matos', url: 'https://www.youtube.com/watch?v=lCcwn6bGUtU', length: 227, playlist: null, isLive: false}, 50, 13)
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -51,10 +51,10 @@ export default class {
|
|||
return false;
|
||||
}
|
||||
|
||||
private async playClip(guild: Guild, song: QueuedSong, position: number, duration: number): Promise<void> {
|
||||
private async playClip(guild: Guild, member: GuildMember, song: QueuedSong, position: number, duration: number): Promise<void> {
|
||||
const player = this.playerManager.get(guild.id);
|
||||
|
||||
const [channel, n] = getMostPopularVoiceChannel(guild);
|
||||
const [channel, n] = getMemberVoiceChannel(member) ?? getMostPopularVoiceChannel(guild);
|
||||
|
||||
if (!player.voiceConnection && n === 0) {
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Guild, VoiceChannel, User} from 'discord.js';
|
||||
import {Guild, VoiceChannel, User, GuildMember} from 'discord.js';
|
||||
|
||||
export const isUserInVoice = (guild: Guild, user: User): boolean => {
|
||||
let inVoice = false;
|
||||
|
@ -20,6 +20,18 @@ export const getSizeWithoutBots = (channel: VoiceChannel): number => channel.mem
|
|||
return s;
|
||||
}, 0);
|
||||
|
||||
export const getMemberVoiceChannel = (member?: GuildMember): [VoiceChannel, number] | null => {
|
||||
const channel = member?.voice?.channel;
|
||||
if (channel && channel.type === 'voice') {
|
||||
return [
|
||||
channel,
|
||||
getSizeWithoutBots(channel)
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const getMostPopularVoiceChannel = (guild: Guild): [VoiceChannel, number] => {
|
||||
interface PopularResult {
|
||||
n: number;
|
||||
|
|
Loading…
Reference in a new issue