mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-14 05:35:29 +01:00
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
|
import {inject, injectable} from 'inversify';
|
||
|
import {Message} from 'discord.js';
|
||
|
import {TYPES} from '../types';
|
||
|
import PlayerManager from '../managers/player';
|
||
|
import QueueManager from '../managers/queue';
|
||
|
import {getMostPopularVoiceChannel} from '../utils/channels';
|
||
|
|
||
|
@injectable()
|
||
|
export default class {
|
||
|
private readonly playerManager: PlayerManager;
|
||
|
private readonly queueManager: QueueManager;
|
||
|
|
||
|
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||
|
this.playerManager = playerManager;
|
||
|
this.queueManager = queueManager;
|
||
|
}
|
||
|
|
||
|
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 queue = this.queueManager.get(msg.guild!.id);
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
const isPlaying = queue.getCurrent();
|
||
|
let oldPosition = 0;
|
||
|
|
||
|
queue.add({title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false});
|
||
|
|
||
|
if (isPlaying) {
|
||
|
oldPosition = player.getPosition();
|
||
|
queue.forward();
|
||
|
}
|
||
|
|
||
|
await player.seek(8);
|
||
|
|
||
|
return new Promise((resolve, reject) => {
|
||
|
try {
|
||
|
setTimeout(async () => {
|
||
|
if (isPlaying) {
|
||
|
queue.back();
|
||
|
|
||
|
await player.seek(oldPosition);
|
||
|
} else {
|
||
|
queue.forward();
|
||
|
player.disconnect();
|
||
|
}
|
||
|
|
||
|
resolve(true);
|
||
|
}, 10000);
|
||
|
} catch (error) {
|
||
|
reject(error);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|