Join the message sender's channel if possible

This commit is contained in:
Luis Ávila 2021-09-15 23:12:48 +01:00
parent c97206bb8b
commit cd9d5248ac
No known key found for this signature in database
GPG key ID: 88BC24179A6B16E0
3 changed files with 23 additions and 11 deletions

View file

@ -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;