diff options
| author | Max Isom <[email protected]> | 2020-03-27 15:44:49 -0500 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2020-03-27 15:44:49 -0500 |
| commit | a2950ed722d5ed1f0e3d31922d796836ec1b18da (patch) | |
| tree | 20b54bf0bb2b13ccd0810a90bb3d012dc0aa4ca1 | |
| parent | 4e1a156f9be48eaefbd3f6dc09f302db7deaddb2 (diff) | |
| download | muse-a2950ed722d5ed1f0e3d31922d796836ec1b18da.tar.xz muse-a2950ed722d5ed1f0e3d31922d796836ec1b18da.zip | |
Add bears handler and fix natural language handler priority
| -rw-r--r-- | src/bot.ts | 6 | ||||
| -rw-r--r-- | src/services/natural-language-commands.ts | 93 |
2 files changed, 58 insertions, 41 deletions
@@ -48,13 +48,13 @@ export default class { return this.client.emit('guildCreate', msg.guild); } - if (await this.naturalLanguage.execute(msg)) { + const {prefix, channel} = settings; + + if (!msg.content.startsWith(prefix) && !msg.author.bot && msg.channel.id === channel && await this.naturalLanguage.execute(msg)) { // Natural language command handled message return; } - const {prefix, channel} = settings; - if (!msg.content.startsWith(prefix) || msg.author.bot || msg.channel.id !== channel) { return; } diff --git a/src/services/natural-language-commands.ts b/src/services/natural-language-commands.ts index ce89ce0..104cd4f 100644 --- a/src/services/natural-language-commands.ts +++ b/src/services/natural-language-commands.ts @@ -1,7 +1,8 @@ import {inject, injectable} from 'inversify'; -import {Message} from 'discord.js'; +import {Message, Guild} from 'discord.js'; import {TYPES} from '../types'; import PlayerManager from '../managers/player'; +import {QueuedSong} from '../services/player'; import {getMostPopularVoiceChannel} from '../utils/channels'; @injectable() @@ -20,56 +21,72 @@ export default class { return true; } - if (msg.content.includes('packers')) { - const player = this.playerManager.get(msg.guild!.id); + 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) + ]); - const [channel, n] = getMostPopularVoiceChannel(msg.guild!); + return true; + } - await msg.channel.send('GO PACKERS GO!!!'); + 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) + ]); - if (!player.voiceConnection && n === 0) { - return false; - } + return true; + } - if (!player.voiceConnection) { - await player.connect(channel); - } + return false; + } - const isPlaying = player.getCurrent() !== null; - let oldPosition = 0; + private async playClip(guild: Guild, song: QueuedSong, position: number, duration: number): Promise<void> { + const player = this.playerManager.get(guild.id); - player.add({title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false}, {immediate: true}); + const [channel, n] = getMostPopularVoiceChannel(guild); - if (isPlaying) { - oldPosition = player.getPosition(); + if (!player.voiceConnection && n === 0) { + return; + } - player.manualForward(); - } + if (!player.voiceConnection) { + await player.connect(channel); + } - await player.seek(8); + const isPlaying = player.getCurrent() !== null; + let oldPosition = 0; - return new Promise((resolve, reject) => { - try { - setTimeout(async () => { - if (player.getCurrent()?.title === 'GO PACKERS!') { - player.removeCurrent(); + player.add(song, {immediate: true}); - if (isPlaying) { - await player.back(); - await player.seek(oldPosition); - } else { - player.disconnect(); - } - } + if (isPlaying) { + oldPosition = player.getPosition(); - resolve(true); - }, 10000); - } catch (error) { - reject(error); - } - }); + player.manualForward(); } - return false; + await player.seek(position); + + return new Promise((resolve, reject) => { + try { + setTimeout(async () => { + if (player.getCurrent()?.title === song.title) { + player.removeCurrent(); + + if (isPlaying) { + await player.back(); + await player.seek(oldPosition); + } else { + player.disconnect(); + } + } + + resolve(); + }, duration * 1000); + } catch (error) { + reject(error); + } + }); } } |
