Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit b3a4ace90ac3be1ab757157306cc2c00ffdd920d
parent 70601d4239e694b2b332ad01ca0b4e5af82f675a
Author: Demonstrandum <moi@knutsen.co>
Date:   Sat, 21 Nov 2020 19:37:01 +0000

Add HELP entries, and try and refetch media if prefetches have been lost.

Diffstat:
MHELP.md | 14++++++++++++++
Mlib/commands/vc.ts | 18++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/HELP.md b/HELP.md @@ -81,6 +81,19 @@ - `!git stars` — Get star count. - `!git watches` — Get watch count. - `!git forks` — Get fork count. +- `!vc` — Voice Chat commands: + - `!vc [url]` — Downloads and media at URL and adds it to the media queue. + - `!vc join` — Joins the voice channel you are in. + - `!vc leave` — Leaves the voice channel. + - `!vc ls` — Lists the media in the queue. + - `!vc d [index]` — Deletes media from queue at index. + - `!vc i [index] [url]` — Inserts media from URL at index. + - `!vc play` — Start playing media from the queue. + - `!vc pause` — Pause playback. + - `!vc skip` — Skip the current media, and proceed to next. + - `!vc requeue` — Clears the queue. +- `!tts` — Text To Speech (bot needs to have joined voice channel): + - `!tts [sentence ...]` — Say sentence. - `!choose [comma-separated-values]` — Choose randomly from a list of items, separated by commas. - `!define [word]` — Looks a word up in the Oxford English Dictionary. - `!urban [slang]` — Looks up a piece of slang in the _Urban Dictionary_. @@ -125,6 +138,7 @@ - `!emojis` — Lists all the emojis on the server. - `!hangman <options>` **〈not impl.〉** — Hangman game to play with your friends. - `!code [!command]` — Shows the source code of a certain command. +- `!abbreviate [words]` — Abbreviates a series of words into an initialism/acronym. ▬▬▬ diff --git a/lib/commands/vc.ts b/lib/commands/vc.ts @@ -1,4 +1,5 @@ import { TextChannel } from 'discord.js'; +import * as stream from 'stream'; import * as cp from 'child_process'; const YTDL_OPTIONS = [ @@ -53,6 +54,19 @@ export default async (home_scope: HomeScope) => { return false; }; + const get_prefetch = (url: string): stream.Readable => { + let fetched = undefined; + if (GID.vc_prefetch.hasOwnProperty(url)) + fetched = GID.vc_prefetch[url]; + if (fetched === null) + return null + if (!fetched) { + attempt_prefetch(url); + fetcged = GID.vc_prefetch[url]; + } + return fetched; + }; + switch (args[0]) { case "join": { if (message.member.voice.channel) { @@ -109,7 +123,7 @@ export default async (home_scope: HomeScope) => { return; } const next = CONFIG.vc_queue.shift(); - const stream = GID.vc_prefetch[next]; + const stream = get_prefetch(next); GID.vc_current_stream = stream; GID.vc_dispatcher = GID.vc.play(stream); set_event_listeners(); @@ -135,7 +149,7 @@ export default async (home_scope: HomeScope) => { }); }; - const stream = GID.vc_prefetch[CONFIG.vc_queue.shift()]; + const stream = get_prefetch(CONFIG.vc_queue.shift()); GID.vc_current_stream = stream; GID.vc_dispatcher = GID.vc.play(stream); message.channel.send("Playing media from queue...");