Simp-O-Matic

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

commit ff4f33d718ff0ad5b4001b5b7a7c62d9a37ebb60
parent fcaf53956caaf3bec39c8d60aff377eb01239bb1
Author: Fredrik <moi@knutsen.co>
Date:   Tue, 10 Nov 2020 22:35:04 +0000

Merge pull request #26 from Demonstrandum/vc-beta


Diffstat:
Alib/commands/vc.ts | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlib/default.ts | 4++++
Mlib/extensions.ts | 4++++
Mpackage.json | 3++-
Mtsconfig.json | 2+-
5 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/lib/commands/vc.ts b/lib/commands/vc.ts @@ -0,0 +1,66 @@ +const ytdl = require("ytdl-core"); +export default async(home_scope: HomeScope) => { + const { message, args, CONFIG } = home_scope; + if(!message.guild) { + message.answer("Just use youtube-dl at home."); + return; + }; + if(!CONFIG.vcqueue) + CONFIG.vcqueue = []; + switch(args[0]){ + case "join": + if(message.member.voice.channel){ + CONFIG.vc = await message.member.voice.channel.join(); + CONFIG.vcc = message.channel; + } + else + message.reply("Join A Channel First."); + break; + case "leave": + try{ + CONFIG.vc.disconnect(); + } catch (error){ + message.answer(error); + } + break; + case "pause": + if(CONFIG.vcdispatcher) + CONFIG.vcdispatcher.pause(); + else + message.answer("Nothing is playng"); + break; + case "play": + if(CONFIG.vcdispatcher) + CONFIG.vcdispatcher.resume(); + else{ + CONFIG.vcdispatcher = CONFIG.vc.play(ytdl(CONFIG.vcqueue.pop(), { filter: 'audioonly' })); + CONFIG.vcdispatcher.on("finish", () => { + CONFIG.vcdispatcher.destroy(); + let next = CONFIG.vcqueue.pop(); + if(next){ + CONFIG.vcdispatcher = CONFIG.vc.play(ytdl(CONFIG.vcqueue.pop(), { filter: 'audioonly' })); + CONFIG.vcc.send("Now playing: " + next) + } + }) + } + break; + case "d": + case "i": + const splice_args : any = args[0] == 'd' ? [1] : [0, args[2]]; + CONFIG.vcqueue = CONFIG.vcqueue.splice(Number(args[1]), ...splice_args); + case "ls": + message.answer(ls(CONFIG)); + break; + case "requeue": + CONFIG.vcqueue = []; + message.answer("Queue cleared"); + case "skip": + CONFIG.vcdispatcher.end(); + break; + default: + CONFIG.vcqueue.push(args[0]); //add checking for valid URIs? + } +} +function ls(CONFIG : Types.Config){ //this could be more sophisticated + return "length: " + CONFIG.vcqueue.length + CONFIG.vcqueue.map((a, b) => "\n" + b + ": " + a).join(""); +} diff --git a/lib/default.ts b/lib/default.ts @@ -14,6 +14,10 @@ const DEFAULT_GUILD_CONFIG : Types.Config = { rape: 0 } }, + vc: null, + vcc: null, + vcqueue: null, + vcdispatcher: null, pp_sizes: { '541761315887120399': 16, '265958795254038535': 36 diff --git a/lib/extensions.ts b/lib/extensions.ts @@ -49,6 +49,10 @@ declare global { [key: string]: string }, stats: Stats, + vc: any, + vcc: any, + vcqueue: any[], + vcdispatcher: any, commands: { prefix: string, max_history: number, diff --git a/package.json b/package.json @@ -58,7 +58,8 @@ "scrape-youtube": "0.2.0", "tslib": "^1.11.1", "typescript": "^3.8.3", - "unirest": "^0.6.0" + "unirest": "^0.6.0", + "ytdl-core": "^4.0.3" }, "devDependencies": { "tslint": "^6.1.0" diff --git a/tsconfig.json b/tsconfig.json @@ -39,7 +39,7 @@ "noUnusedLocals": false, /* Report errors on unused locals. */ "noUnusedParameters": false, /* Report errors on unused parameters. */ "noImplicitReturns": false, /* Report error when not all code paths in function return a value. */ - "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + "noFallthroughCasesInSwitch": false, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */