Skip to content

Commit

Permalink
bot is partially fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasMarq committed Oct 29, 2021
1 parent 46615dd commit 27791ed
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 83 deletions.
36 changes: 19 additions & 17 deletions src/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { injectable } from "inversify";
import config from 'config';
import { Command, CommandMessage, Discord, CommandNotFound } from "@typeit/discord";
import {SimpleCommand, SimpleCommandMessage, SimpleCommandOption} from 'discordx'
import {Discord, SimpleCommand, SimpleCommandMessage, SimpleCommandOption} from 'discordx'
import Message from "./message";
import Log from "../util/log";
import Voice from './voice';

const BOT_PREFIX: string = config.get('bot_config.prefix')

@Discord(BOT_PREFIX)
@Discord()
@injectable()
export default class Events {
private message: Message;
Expand All @@ -27,9 +26,10 @@ export default class Events {
this.voice.clearQueueCommand(command.message);
}

@SimpleCommand('play :url')
private async playMusicCommand(command: SimpleCommandMessage) {
this.voice.playMusicCommand(command.message);
@SimpleCommand('play')
private async playMusicCommand(@SimpleCommandOption('url', {type: 'STRING'}) url: string | undefined,
command: SimpleCommandMessage) {
this.voice.playMusicCommand(url, command.message);
}

@SimpleCommand('pause')
Expand All @@ -47,9 +47,10 @@ export default class Events {
this.voice.nowPlayingCommand(command.message);
}

@SimpleCommand('volume :value')
private volumeCommand(command: SimpleCommandMessage) {
this.voice.volumeCommand(command.message);
@SimpleCommand('volume')
private volumeCommand(@SimpleCommandOption('value', {type: 'INTEGER'}) value: number | undefined,
command: SimpleCommandMessage) {
this.voice.volumeCommand(value, command.message);
}

@SimpleCommand('leave')
Expand Down Expand Up @@ -90,25 +91,26 @@ export default class Events {
this.message.helloCommand(command.message);
}

@SimpleCommand('purge :number')
private bulkDeleteCommand(command: SimpleCommandMessage) {
this.message.bulkDeleteCommand(command.message);
@SimpleCommand('purge')
private bulkDeleteCommand(@SimpleCommandOption(`number`, {type: 'INTEGER'}) number: number | undefined,
command: SimpleCommandMessage) {
this.message.bulkDeleteCommand(number, command.message);
}

@SimpleCommand('help')
private helpCommand(command: SimpleCommandMessage) {
this.message.helpCommand(command.message);
}

@SimpleCommandNotFound()
private notFound(command: SimpleCommandMessage) {
message.reply(`Comando não existente. Digite ${BOT_PREFIX}help`);
}
// @SimpleCommandNotFound()
// private notFound(command: SimpleCommandMessage) {
// command.message.reply(`Comando não existente. Digite ${BOT_PREFIX}help`);
// }

@SimpleCommand('cagaram')
private cagaramNoEstojoDoLeo(command: SimpleCommandMessage){
// message.reply(`Cagaram no estojo do <@243107174186876930> denovo? Q otario haha`);me marca
message.channel.send('Cagaram no estojo do <@243107174186876930> denovo? Q otario haha');
command.message.channel.send('Cagaram no estojo do <@243107174186876930> denovo? Q otario haha');
}

//-------------------------- OTHERS --------------------------
Expand Down
16 changes: 7 additions & 9 deletions src/events/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from 'config';
import { Discord, SimpleCommand, SimpleCommandMessage, SimpleCommandOption } from 'discordx';
import { Message as msg } from 'discord.js';

@Discord()
export default class Message {
Expand All @@ -12,20 +13,17 @@ export default class Message {
this.whitelist = config.get('bot_config.whitelist');
}

@SimpleCommand("hello")
public helloCommand(command: SimpleCommandMessage) {
public helloCommand(message: msg) {
// if (!this.whitelist[message.channel.id]) return;
command.message.reply(`Hello.`);
message.reply(`Hello.`);
}

@SimpleCommand("help")
public helpCommand(command: SimpleCommandMessage) {
command.message.reply(`!help`);
public helpCommand(message: msg) {
message.reply(`!help`);
}

@SimpleCommand("purge")
public bulkDeleteCommand(@SimpleCommandOption("number", {type: "NUMBER"}) number: number | undefined, command: SimpleCommandMessage) {
if (!number) command.message.reply('Uso: !purge <<numero de mensagens aqui, limitado à 100>>');
public bulkDeleteCommand(number: number | undefined, message: msg) {
if (!number) message.reply('Uso: !purge <<numero de mensagens aqui, limitado à 100>>');

// if (number > 100) command.message.reply('Limitado a 100 mensagens.');
// else command.message.channel.bulkDelete();
Expand Down
115 changes: 58 additions & 57 deletions src/events/voice/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import config from 'config';
import { StreamDispatcher, VoiceConnection } from "discord.js";
import { CommandMessage, CommandNotFound, Client } from "@typeit/discord";
import { Message } from "discord.js";
import { SimpleCommandMessage } from "discordx"
import { StreamTransportOptions } from 'winston/lib/winston/transports';
import { monitorEventLoopDelay } from 'node:perf_hooks';
import { repeat } from 'lodash';
const ytdl = require('ytdl-core');

export default class Voice {
private actualChannel: CommandMessage | undefined;
private player: VoiceConnection | undefined;
private dispatcher: StreamDispatcher | undefined;
private actualChannel: SimpleCommandMessage | undefined;
// private player: VoiceConnection | undefined;
// private dispatcher: StreamDispatcher | undefined;
private readonly blacklist: any;
private readonly whitelist: any;
private queue: string[];
Expand All @@ -20,56 +19,57 @@ export default class Voice {
this.queue = [];
};

public clearQueueCommand(message: CommandMessage) {
public clearQueueCommand(message: Message) {
if (!this.whitelist[message.channel.id]) return;
this.clearQueueTool();
message.reply('Lista de Música limpa.');
}

public async playMusicCommand(message: CommandMessage) {
public async playMusicCommand(url: string | undefined, message: Message) {
if (!this.whitelist[message.channel.id]) return;
message.delete({reason: 'delete play command'});
this.player = await message.member?.voice.channel?.join();
this.queue.push(message.args.url);
if(!url) return;
message.channel.delete('delete play command');
// this.player = await message.member?.voice.channel?.join();
this.queue.push(url);

if (this.queue.length < 2) {
this.actualChannel = message;
// this.actualChannel = message;
this.playMusic();
}
}

private playMusic() {
if(this.actualChannel) this.actualChannel.reply(`Agora está tocando ${this.queue[0]}`);
this.player?.play(ytdl(this.queue[0])).on('finish', () => {
this.queue = this.queue.splice(1);
if (this.queue.length !== 0) this.playMusic();
});
// if(this.actualChannel) this.actualChannel.message.reply(`Agora está tocando ${this.queue[0]}`);
// this.player?.play(ytdl(this.queue[0])).on('finish', () => {
// this.queue = this.queue.splice(1);
// if (this.queue.length !== 0) this.playMusic();
// });
}

public skipCommand(message: CommandMessage){
if (!this.whitelist[message.channel.id]) return;
if(this.queue.length > 2){
this.queue = this.queue.splice(1);
this.playMusic();
} else {
this.clearQueueTool();
message.member?.voice.channel?.leave();
}
public skipCommand(message: Message){
// if (!this.whitelist[message.channel.id]) return;
// if(this.queue.length > 2){
// this.queue = this.queue.splice(1);
// this.playMusic();
// } else {
// this.clearQueueTool();
// // message.member?.voice.channel?.leave();
// }
}

public stopCommand(message: CommandMessage){
if (!this.whitelist[message.channel.id]) return;
this.player?.dispatcher.end();
this.clearQueueTool();
message.reply(`Parei de tocar? Bota outro som ae :D`)
public stopCommand(message: Message){
// if (!this.whitelist[message.channel.id]) return;
// this.player?.dispatcher.end();
// this.clearQueueTool();
// message.reply(`Parei de tocar? Bota outro som ae :D`)
}

public shuffleCommand(message: CommandMessage){
public shuffleCommand(message: Message){
if (!this.whitelist[message.channel.id]) return;
this.queue = this.shuffle(this.queue);
// this.queue = this.shuffle(this.queue);
}

public showQueueCommand(message: CommandMessage){
public showQueueCommand(message: Message){
if (!this.whitelist[message.channel.id]) return;
if(this.queue.length < 1) message.reply('Não há itens na fila de musica.');
else {
Expand All @@ -83,53 +83,54 @@ export default class Voice {
}
}

public pauseCommand(message: CommandMessage) {
if (!this.whitelist[message.channel.id]) return;
this.player?.dispatcher.pause();
message.reply('pausado.');
public pauseCommand(message: Message) {
// if (!this.whitelist[message.channel.id]) return;
// this.player?.dispatcher.pause();
// message.reply('pausado.');
}

public resumeCommand(message: CommandMessage) {
if (!this.whitelist[message.channel.id]) return;
this.player?.dispatcher?.resume();
message.reply('resumido.');
public resumeCommand(message: Message) {
// if (!this.whitelist[message.channel.id]) return;
// this.player?.dispatcher?.resume();
// message.reply('resumido.');
}

public nowPlayingCommand(message: CommandMessage) {
public nowPlayingCommand(message: Message) {
if (!this.whitelist[message.channel.id]) return;
// to@do
}

public loopCommand(message: CommandMessage){
public loopCommand(message: Message){
if (!this.whitelist[message.channel.id]) return;
//to@do
}


public volumeCommand(message: CommandMessage) {
public volumeCommand(value: number | undefined, message: Message) {
if (!this.whitelist[message.channel.id]) return;
let bool: any = message.args.value > 100 ? ((message.args.value = 100) / 100) : (message.args.value / 100);
if (!value) return;
let bool: any = value > 100 ? ((value = 100) / 100) : (value / 100);
if (bool < 0) bool = 0;
this.dispatcher?.setVolume(bool);
// this.dispatcher?.setVolume(bool);
message.reply(`Colocando o volume em ${bool * 100}%`);
}

public leaveVoiceCommand(message: CommandMessage) {
public leaveVoiceCommand(message: Message) {
if (!this.whitelist[message.channel.id]) return;
this.clearQueueTool();
message.member?.voice.channel?.leave();
// message.member?.voice.channel?.leave();
}

private shuffle(a: string[]) {
let aux = a.shift();
for (let i = a.length - 1; i > 0; i--) {
if(i === 0) continue;
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
if(aux) a.unshift(aux);
if(this.actualChannel)(this.showQueueCommand(this.actualChannel))
return a;
// let aux = a.shift();
// for (let i = a.length - 1; i > 0; i--) {
// if(i === 0) continue;
// const j = Math.floor(Math.random() * (i + 1));
// [a[i], a[j]] = [a[j], a[i]];
// }
// if(aux) a.unshift(aux);
// if(this.actualChannel)(this.showQueueCommand(this.actualChannel))
// return a;
}

private clearQueueTool() {
Expand Down

0 comments on commit 27791ed

Please sign in to comment.