Skip to content

Commit

Permalink
converting from @typeit/discord to discordx
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasMarq committed Oct 29, 2021
1 parent 6f98ef2 commit 46615dd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 68 deletions.
10 changes: 7 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import { inject, injectable } from "inversify";
import Events from "../events";
import config from 'config';
import { Discord } from "@typeit/discord";
import { Client, Discord } from "discordx";

@Discord(config.get('bot_config.prefix'))
@Discord()
@injectable()
export default class Core {
private core: Client
constructor(@inject(Events) private readonly events: Events
) {

// Look into this bug or programming error, otherwise report it at discordx github!
// @ts-ignore
this.core = new Client({ botId: 'NITRA Bot' });
this.core.login(config.get('secrets.token'));
}
}
99 changes: 50 additions & 49 deletions src/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { injectable } from "inversify";
import config from 'config';
import { Command, CommandMessage, Discord, CommandNotFound } from "@typeit/discord";
import {SimpleCommand, SimpleCommandMessage, SimpleCommandOption} from 'discordx'
import Message from "./message";
import Log from "../util/log";
import Voice from './voice';
Expand All @@ -21,91 +22,91 @@ export default class Events {
}

//-------------------------- VOICE --------------------------
@Command('clear')
private clearCommand(message: CommandMessage) {
this.voice.clearQueueCommand(message);
@SimpleCommand('clear')
private clearCommand(command: SimpleCommandMessage) {
this.voice.clearQueueCommand(command.message);
}

@Command('play :url')
private async playMusicCommand(message: CommandMessage) {
this.voice.playMusicCommand(message);
@SimpleCommand('play :url')
private async playMusicCommand(command: SimpleCommandMessage) {
this.voice.playMusicCommand(command.message);
}

@Command('pause')
private pauseCommand(message: CommandMessage) {
this.voice.pauseCommand(message);
@SimpleCommand('pause')
private pauseCommand(command: SimpleCommandMessage) {
this.voice.pauseCommand(command.message);
}

@Command('resume')
private resumeCommand(message: CommandMessage) {
this.voice.resumeCommand(message);
@SimpleCommand('resume')
private resumeCommand(command: SimpleCommandMessage) {
this.voice.resumeCommand(command.message);
}

@Command('playing')
private nowPlaying(message: CommandMessage) {
this.voice.nowPlayingCommand(message);
@SimpleCommand('playing')
private nowPlaying(command: SimpleCommandMessage) {
this.voice.nowPlayingCommand(command.message);
}

@Command('volume :value')
private volumeCommand(message: CommandMessage) {
this.voice.volumeCommand(message);
@SimpleCommand('volume :value')
private volumeCommand(command: SimpleCommandMessage) {
this.voice.volumeCommand(command.message);
}

@Command('leave')
private leaveVoiceCommand(message: CommandMessage) {
this.voice.leaveVoiceCommand(message);
@SimpleCommand('leave')
private leaveVoiceCommand(command: SimpleCommandMessage) {
this.voice.leaveVoiceCommand(command.message);
}

@Command('skip')
private skipCommand(message: CommandMessage){
this.voice.skipCommand(message);
@SimpleCommand('skip')
private skipCommand(command: SimpleCommandMessage){
this.voice.skipCommand(command.message);
}

@Command('queue')
private showQueueCommand(message: CommandMessage){
this.voice.showQueueCommand(message);
@SimpleCommand('queue')
private showQueueCommand(command: SimpleCommandMessage){
this.voice.showQueueCommand(command.message);
}

@Command('shuffle')
private shuffleCommand(message: CommandMessage){
this.voice.shuffleCommand(message);
@SimpleCommand('shuffle')
private shuffleCommand(command: SimpleCommandMessage){
this.voice.shuffleCommand(command.message);
}

@Command('stop')
private stopCommand(message: CommandMessage){
this.voice.stopCommand(message)
@SimpleCommand('stop')
private stopCommand(command: SimpleCommandMessage){
this.voice.stopCommand(command.message)
}

@Command('loop')
private loopCommand(message: CommandMessage){
this.voice.loopCommand(message)
@SimpleCommand('loop')
private loopCommand(command: SimpleCommandMessage){
this.voice.loopCommand(command.message)
}


//-------------------------- MESSAGE --------------------------

@Command('hello')
private helloCommand(message: CommandMessage) {
this.message.helloCommand(message);
@SimpleCommand('hello')
private helloCommand(command: SimpleCommandMessage) {
this.message.helloCommand(command.message);
}

@Command('purge :number')
private bulkDeleteCommand(message: CommandMessage) {
this.message.bulkDeleteCommand(message);
@SimpleCommand('purge :number')
private bulkDeleteCommand(command: SimpleCommandMessage) {
this.message.bulkDeleteCommand(command.message);
}

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

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

@Command('cagaram')
private cagaramNoEstojoDoLeo(message: CommandMessage){
@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');
}
Expand Down
27 changes: 15 additions & 12 deletions src/events/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import config from 'config';
import { Command, CommandMessage, CommandNotFound } from "@typeit/discord";
import { Discord, SimpleCommand, SimpleCommandMessage, SimpleCommandOption } from 'discordx';

@Discord()
export default class Message {
private readonly blacklist: any;
private readonly whitelist: any;
Expand All @@ -11,20 +12,22 @@ export default class Message {
this.whitelist = config.get('bot_config.whitelist');
}

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

public helpCommand(message: CommandMessage) {
if(!this.commands.has(message.commandContent)) return;
let getCommand = this.commands.get(message.commandContent);
if(getCommand) message.reply(getCommand);
@SimpleCommand("help")
public helpCommand(command: SimpleCommandMessage) {
command.message.reply(`!help`);
}

public bulkDeleteCommand(message: CommandMessage) {
let number = message.args.number;
if(number > 100) message.reply('Limitado a 100 mensagens.');
else message.channel.messages.channel.bulkDelete(number);
@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>>');

// if (number > 100) command.message.reply('Limitado a 100 mensagens.');
// else command.message.channel.bulkDelete();
}
}
2 changes: 2 additions & 0 deletions src/events/voice/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import config from 'config';
import { StreamDispatcher, VoiceConnection } from "discord.js";
import { CommandMessage, CommandNotFound, Client } from "@typeit/discord";
import { SimpleCommandMessage } from "discordx"
import { StreamTransportOptions } from 'winston/lib/winston/transports';
import { monitorEventLoopDelay } from 'node:perf_hooks';
import { repeat } from 'lodash';
Expand Down Expand Up @@ -30,6 +31,7 @@ export default class Voice {
message.delete({reason: 'delete play command'});
this.player = await message.member?.voice.channel?.join();
this.queue.push(message.args.url);

if (this.queue.length < 2) {
this.actualChannel = message;
this.playMusic();
Expand Down
5 changes: 1 addition & 4 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'reflect-metadata';
import { Client } from "@typeit/discord"
import { inject, injectable } from 'inversify';
import Log from '../util/log';
import config from 'config'
Expand All @@ -8,7 +7,7 @@ import http from '../util/http';

@injectable()
export default class Server {
Client: Client;

private readonly log: Log;
private readonly core: Core;
constructor(
Expand All @@ -18,8 +17,6 @@ export default class Server {
this.core = core;
this.log = log;
this.log.debug('Iniciando..........');
this.Client = new Client();
this.Client.login(config.get('secrets.token'));
}
}

0 comments on commit 46615dd

Please sign in to comment.