Add bears handler and fix natural language handler priority

This commit is contained in:
Max Isom 2020-03-27 15:44:49 -05:00
parent 4e1a156f9b
commit a2950ed722
2 changed files with 66 additions and 49 deletions

View file

@ -48,13 +48,13 @@ export default class {
return this.client.emit('guildCreate', msg.guild); 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 // Natural language command handled message
return; return;
} }
const {prefix, channel} = settings;
if (!msg.content.startsWith(prefix) || msg.author.bot || msg.channel.id !== channel) { if (!msg.content.startsWith(prefix) || msg.author.bot || msg.channel.id !== channel) {
return; return;
} }

View file

@ -1,7 +1,8 @@
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import {Message} from 'discord.js'; import {Message, Guild} from 'discord.js';
import {TYPES} from '../types'; import {TYPES} from '../types';
import PlayerManager from '../managers/player'; import PlayerManager from '../managers/player';
import {QueuedSong} from '../services/player';
import {getMostPopularVoiceChannel} from '../utils/channels'; import {getMostPopularVoiceChannel} from '../utils/channels';
@injectable() @injectable()
@ -20,15 +21,34 @@ export default class {
return true; return true;
} }
if (msg.content.includes('packers')) { if (msg.content.toLowerCase().includes('packers')) {
const player = this.playerManager.get(msg.guild!.id); 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)
]);
return true;
}
return false;
}
private async playClip(guild: Guild, song: QueuedSong, position: number, duration: number): Promise<void> {
const player = this.playerManager.get(guild.id);
const [channel, n] = getMostPopularVoiceChannel(guild);
if (!player.voiceConnection && n === 0) { if (!player.voiceConnection && n === 0) {
return false; return;
} }
if (!player.voiceConnection) { if (!player.voiceConnection) {
@ -38,7 +58,7 @@ export default class {
const isPlaying = player.getCurrent() !== null; const isPlaying = player.getCurrent() !== null;
let oldPosition = 0; let oldPosition = 0;
player.add({title: 'GO PACKERS!', artist: 'Unknown', url: 'https://www.youtube.com/watch?v=qkdtID7mY3E', length: 204, playlist: null, isLive: false}, {immediate: true}); player.add(song, {immediate: true});
if (isPlaying) { if (isPlaying) {
oldPosition = player.getPosition(); oldPosition = player.getPosition();
@ -46,12 +66,12 @@ export default class {
player.manualForward(); player.manualForward();
} }
await player.seek(8); await player.seek(position);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
setTimeout(async () => { setTimeout(async () => {
if (player.getCurrent()?.title === 'GO PACKERS!') { if (player.getCurrent()?.title === song.title) {
player.removeCurrent(); player.removeCurrent();
if (isPlaying) { if (isPlaying) {
@ -62,14 +82,11 @@ export default class {
} }
} }
resolve(true); resolve();
}, 10000); }, duration * 1000);
} catch (error) { } catch (error) {
reject(error); reject(error);
} }
}); });
} }
return false;
}
} }