2020-03-18 23:15:45 +01:00
|
|
|
import {inject, injectable} from 'inversify';
|
|
|
|
import {Message} from 'discord.js';
|
|
|
|
import {TYPES} from '../types';
|
|
|
|
import PlayerManager from '../managers/player';
|
|
|
|
import {getMostPopularVoiceChannel} from '../utils/channels';
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export default class {
|
|
|
|
private readonly playerManager: PlayerManager;
|
|
|
|
|
2020-03-21 02:47:04 +01:00
|
|
|
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
2020-03-18 23:15:45 +01:00
|
|
|
this.playerManager = playerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute(msg: Message): Promise<boolean> {
|
|
|
|
if (msg.content.startsWith('say') && msg.content.endsWith('muse')) {
|
|
|
|
const res = msg.content.slice(3, msg.content.indexOf('muse')).trim();
|
|
|
|
|
|
|
|
await msg.channel.send(res);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.content.includes('packers')) {
|
|
|
|
const player = this.playerManager.get(msg.guild!.id);
|
|
|
|
|
|
|
|
const [channel, n] = getMostPopularVoiceChannel(msg.guild!);
|
|
|
|
|
|
|
|
await msg.channel.send('GO PACKERS GO!!!');
|
|
|
|
|
|
|
|
if (!player.voiceConnection && n === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!player.voiceConnection) {
|
|
|
|
await player.connect(channel);
|
|
|
|
}
|
|
|
|
|
2020-03-21 02:47:04 +01:00
|
|
|
const isPlaying = player.getCurrent() !== null;
|
2020-03-18 23:15:45 +01:00
|
|
|
let oldPosition = 0;
|
|
|
|
|
2020-03-21 02:47:04 +01:00
|
|
|
player.add({title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false}, {immediate: true});
|
2020-03-18 23:15:45 +01:00
|
|
|
|
|
|
|
if (isPlaying) {
|
|
|
|
oldPosition = player.getPosition();
|
2020-03-21 02:47:04 +01:00
|
|
|
|
|
|
|
await player.forward();
|
2020-03-18 23:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await player.seek(8);
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
setTimeout(async () => {
|
2020-03-21 02:47:04 +01:00
|
|
|
player.removeCurrent();
|
2020-03-18 23:15:45 +01:00
|
|
|
|
2020-03-19 04:29:43 +01:00
|
|
|
if (isPlaying) {
|
2020-03-21 02:47:04 +01:00
|
|
|
await player.back();
|
2020-03-18 23:15:45 +01:00
|
|
|
await player.seek(oldPosition);
|
|
|
|
} else {
|
|
|
|
player.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(true);
|
|
|
|
}, 10000);
|
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|