Skip to content

Commit

Permalink
port most of hydro bot
Browse files Browse the repository at this point in the history
  • Loading branch information
aidangoettsch committed Feb 5, 2021
1 parent 3baddc9 commit c7a3ad4
Show file tree
Hide file tree
Showing 39 changed files with 1,090 additions and 652 deletions.
227 changes: 226 additions & 1 deletion common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"./esm": "./esm/discord.mjs"
},
"scripts": {
"build": "",
"test": "npm run lint && npm run docs:test && npm run lint:typings",
"test:typescript": "tsc",
"docs": "docgen --source src --custom docs/index.yml --output docs/docs.json",
Expand Down
8 changes: 5 additions & 3 deletions discord.js/src/client/websocket/WebSocketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class WebSocketManager extends EventEmitter {
...(await this.client.api.gateway.get().catch(error => {
throw error.httpStatus === 401 ? invalidToken : error;
})),
recommendedShards: 1,
sessionStartLimit: {},
shards: 1,
session_start_limit: {},
};

this.sessionStartLimit = sessionStartLimit;
Expand Down Expand Up @@ -170,7 +170,9 @@ class WebSocketManager extends EventEmitter {
this.debug(`Spawning shards: ${shards.join(', ')}`);
this.shardQueue = new Set(shards.map(id => new WebSocketShard(this, id)));

await this._handleSessionLimit(remaining, reset_after);
if (this.client.options.tokenType === 'Bot') {
await this._handleSessionLimit(remaining, reset_after);
}

return this.createShards();
}
Expand Down
5 changes: 3 additions & 2 deletions discord.js/src/structures/VoiceChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ class VoiceChannel extends GuildChannel {

/**
* Attempts to join this voice channel.
* @param {boolean} video If video should be enabled
* @returns {Promise<VoiceConnection>}
* @example
* // Join a voice channel
* voiceChannel.join()
* .then(connection => console.log('Connected!'))
* .catch(console.error);
*/
join() {
return this.client.voice.joinChannel(this);
join(video) {
return this.client.voice.joinChannel(this, video);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ declare module 'discord.js' {
public readonly speakable: boolean;
public type: 'voice';
public userLimit: number;
public join(): Promise<VoiceConnection>;
public join(video: boolean): Promise<VoiceConnection>;
public leave(): void;
public setBitrate(bitrate: number, reason?: string): Promise<VoiceChannel>;
public setUserLimit(userLimit: number, reason?: string): Promise<VoiceChannel>;
Expand Down Expand Up @@ -1647,7 +1647,13 @@ declare module 'discord.js' {
public joinStream(user: User): Promise<StreamConnection>;
public stream(user: User): Promise<StreamConnection>;
public play(input: VoiceBroadcast | Readable | string, options?: StreamOptions): StreamDispatcher;
public playVideo(input: VoiceBroadcast | Readable | string, options?: StreamOptions): VideoDispatcher;
public playVideo(input: VoiceBroadcast | Readable | string | {
audio?: string
video: string
}, options?: StreamOptions): {
video: VideoDispatcher
audio: StreamDispatcher
};
public setSpeaking(value: BitFieldResolvable<SpeakingString>): void;

public on(event: 'authenticated' | 'closing' | 'newSession' | 'ready' | 'reconnecting', listener: () => void): this;
Expand Down Expand Up @@ -3287,9 +3293,13 @@ declare module 'discord.js' {
volume?: number | boolean;
plp?: number;
fec?: boolean;
bitrate?: number | 'auto';
bitrate?: number | string;
highWaterMark?: number;
live?: boolean;
useNvenc?: boolean;
useVaapi?: boolean;
rtBufferSize?: string;
audioDelay?: number;
}

type SpeakingString = 'SPEAKING' | 'SOUNDSHARE' | 'PRIORITY_SPEAKING';
Expand Down
14 changes: 0 additions & 14 deletions hydro-bot/build/config/config.json

This file was deleted.

19 changes: 0 additions & 19 deletions hydro-bot/build/package.json

This file was deleted.

52 changes: 0 additions & 52 deletions hydro-bot/build/src/bot.js

This file was deleted.

26 changes: 0 additions & 26 deletions hydro-bot/build/src/modules/Logger.js

This file was deleted.

11 changes: 7 additions & 4 deletions hydro-bot/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"token": "MjU3NTg2MDk1ODA0NTE0MzA0.XshNnw.Atf_mgG0OfEIF3iDzliWJck4nVY",
"videoToken": "MjAwNzA5OTk5NzM4MDkzNTY4.XpKa0g.33QJsN-NmsK3OLHzqV1CMb2_bEY",
"prefix": "$",
"debug": false,
"queuePageLength": 5,
"video": {
"resolutionMax": 1440,
"resolutionSoftMin": 720,
"bitrate": "4M",
"useNvenc": true,
"useVaapi": false,
"coupledAudioDelay": 0,
"separateAudioDelay": 200,
"liveDelay": 150
"separateAudioDelay": 0,
"rtBufferSize": "4M",
"searchLimit": 5
}
}
}
11 changes: 9 additions & 2 deletions hydro-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "node build/src/bot.js",
"start": "node build/bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
Expand All @@ -15,6 +15,13 @@
"@types/ws": "^7.2.5",
"chalk": "^4.1.0",
"discord.js": "^12.2.0",
"time-stamp": "^2.2.0"
"time-stamp": "^2.2.0",
"debug": "~4.3.1",
"ytdl-core": "~4.4.5",
"youtube-dl": "~3.1.0",
"@types/youtube-dl": "~3.0.0"
},
"devDependencies": {
"@types/debug": "~4.1.5"
}
}
40 changes: 40 additions & 0 deletions hydro-bot/src/CommandHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Discord from "discord.js"
import {Bot} from "./bot";
import GuildState from "./guild/GuildState";
import Help from "./commands/Help";
import Leave from "./commands/Leave";
import NowPlaying from "./commands/NowPlaying";
import Play from "./commands/Play";
import Queue from "./commands/Queue";
import Skip from "./commands/Skip";
import Volume from "./commands/Volume";
import Command from "./commands/Command";

const commands = [
Help,
Leave,
NowPlaying,
Play,
Queue,
Skip,
Volume,
]

export default class CommandHandler {
public commands: Command[]
public commandMap: Map<string, Command> = new Map()
constructor(private bot: Bot) {
this.commands = commands.map(c => new c(bot, this))

for (const command of this.commands) {
this.commandMap.set(command.info.command, command)
command.info.alias.forEach(a => this.commandMap.set(a, command))
}
}

execute(commandName: string, msg: Discord.Message, args: string[], state: GuildState): Promise<void> {
const command = this.commandMap.get(commandName)
if (!command) return Promise.reject(new Error("No such command"))
return command.execute(msg, args, state)
}
}
91 changes: 91 additions & 0 deletions hydro-bot/src/EmbedFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {Bot} from "./bot";
import {MessageEmbed, MessageEmbedFooter, MessageEmbedOptions} from "discord.js";
import {DownloaderResult, MediaResult} from "./downloader/Downloader";
import {QueuedMedia} from "./guild/GuildState";

export default class EmbedFactory {
readonly footer: MessageEmbedFooter;
constructor (private bot: Bot) {
this.footer = {
iconURL: bot.profilePicUrl || undefined,
text: `| ${bot.version} - Developed By CF12`
}
}

info(content: string): MessageEmbed {
return new MessageEmbed({
title: ':bulb: __❱❱ INFO ❱❱__',
description: content,
color: 5235199, // Light Blue
footer: this.footer
})
}


error(content: string): MessageEmbed {
return new MessageEmbed({
title: ':warning: __❱❱ ERROR ❱❱__',
description: content,
color: 16731983, // Light Red
footer: this.footer
})
}

volInfo (volume: number): MessageEmbed {
return new MessageEmbed({
title: ':loud_sound: __❱❱ VOLUME ❱❱__',
description: `Volume has been set to: **${(volume).toFixed(0)}%**`,
color: 5753896, // Light Green
footer: this.footer
})
}

static formatDuration = function (duration: number | "live" | "unknown"): string {
if (duration === "live") return "Live"
else if (duration === "unknown") return "Unknown"

const hours = Math.floor(duration / 3600);
const minutes = Math.floor((duration - (hours * 3600)) / 60);
const seconds = duration - (hours * 3600) - (minutes * 60);

return (hours < 10 ? "0" + hours : hours.toString()) +
(minutes < 10 ? "0" + minutes : minutes.toString()) +
(seconds < 10 ? "0" + seconds : seconds.toString())
}

mediaInfo (media: QueuedMedia): MessageEmbed {
return new MessageEmbed({
title: media.title,
description: media.description.length > 180 ? media.description.slice(0, 180) + "..." : media.description,
color: 14038325, // Light Red
author: {
name: 'Now Playing',
iconURL: this.bot.profilePicUrl || undefined
},
thumbnail: {
url: media.thumbnailURL
},
fields: [
{
name: 'Uploaded By:',
value: media.author,
inline: true
},
{
name: 'Duration',
value: EmbedFactory.formatDuration(media.duration),
inline: true
},
{
name: 'Requested By:',
value: media.requester
},
{
name: 'Link',
value: media.videoURL
}
],
footer: this.footer
})
}
}
Loading

0 comments on commit c7a3ad4

Please sign in to comment.