Created
March 5, 2023 12:31
-
-
Save krisppurg/336d5056880891957b9a51f291b887ce to your computer and use it in GitHub Desktop.
voice in my test bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## voice in my test bot | |
## expect some random stuff with some lazy code, im not bothered about it as long as it works lol | |
## note: the code is filtered with only voice related stuff, although there are some parts that are irrelevent or useless | |
## just ignore them. | |
when defined(dimscordStable): | |
import dimscord | |
else: | |
import ../../dimscord/dimscord | |
import json, asyncdispatch, sequtils, ws | |
import strutils, tables, options as optss | |
import random, re, strformat, times, segfaults | |
import httpclient | |
let token = parseJson(readFile("config.json"))["token"].str | |
let discord = newDiscordClient(token) | |
var connected = false | |
var voicedisconnect = false | |
when defined(dimscordVoice): | |
proc voice(v: VoiceClient) {.async.} = | |
try: | |
await v.startSession() | |
except: | |
echo getCurrentExceptionMsg() | |
await voice(v) | |
proc voiceServerUpdate(s: Shard; g: Guild; token: string; | |
endpoint: Option[string], initial: bool) {.event(discord).} = | |
let v = s.voiceConnections[g.id] | |
echo initial | |
v.voice_events.on_ready = proc (vc: VoiceClient) {.async.} = | |
echo "I AM READYYYY" | |
v.offset_override = true | |
if initial: | |
echo vc.connection[] | |
let names = @[ | |
# "Why am i still getting HATE- #DramaAlert.mp4", | |
# "Untitled.mp4", | |
# "MY VOICED DROPPED!.mp4", | |
# "anyways_you_can_stop.mp3", | |
# "Squeezed Lemon Sound Effect.mp3", | |
# "LazyTownWe are Number One Music Video.mp4", | |
] | |
# await vc.playFFmpeg(sample(names)) | |
# await vc.shard.voiceStateUpdate(guild_id = vc.guild_id) | |
# connected = false | |
if initial: await voice(v) | |
proc messageCreate(s: Shard, m: Message) {.event(discord).} = | |
# echo m.content | |
var args = m.content.split(" ") | |
if m.author.bot or not args[0].startsWith("??"): return | |
var command = args[0][2..args[0].len-1] | |
case command.toLowerAscii(): | |
of "join": | |
if args.len > 1: | |
echo s.cache.guilds[m.guild_id.get].channels | |
if args[1] in s.cache.guilds[m.guild_id.get].channels: | |
echo args[1] | |
await s.voiceStateUpdate(m.guild_id.get, ?args[1]) | |
connected = true | |
else: | |
discard await discord.api.sendMessage(m.channel_id, "Incorrect channel ID provided.") | |
else: | |
discard await discord.api.sendMessage(m.channel_id, "You need to provide a channel ID.") | |
of "play": | |
if m.guild_id.isNone: return | |
if not (m.guild_id.get in s.voiceConnections): return | |
let vc = s.voiceConnections[m.guild_id.get] | |
if vc.ready: | |
discard await discord.api.sendMessage(m.channel_id, "playing") | |
asyncCheck vc.voice_events.on_ready(vc) | |
else: | |
return | |
of "ytdl": | |
if args.len == 1: return | |
if m.guild_id.isNone: return | |
if not (m.guild_id.get in s.voiceConnections): return | |
let vc = s.voiceConnections[m.guild_id.get] | |
let link = args[1] | |
if vc.ready: | |
echo "aurora borealis" | |
await vc.playYTDL(link, command = "yt-dlp") | |
else: | |
return | |
of "elapsed": | |
if m.guild_id.isNone: return | |
if not (m.guild_id.get in s.voiceConnections): return | |
let vc = s.voiceConnections[m.guild_id.get] | |
if not vc.ready: return | |
discard await discord.api.sendMessage( | |
m.channel_id, | |
"Elapsed time: " & $vc.elapsed & "s" | |
) | |
of "pause": | |
if m.guild_id.isNone: return | |
if not (m.guild_id.get in s.voiceConnections): return | |
let vc = s.voiceConnections[m.guild_id.get] | |
if vc.ready: | |
vc.pause() | |
discard await discord.api.sendMessage(m.channel_id, "Sound paused.") | |
of "resume": | |
if m.guild_id.isNone: return | |
if not (m.guild_id.get in s.voiceConnections): return | |
let vc = s.voiceConnections[m.guild_id.get] | |
if vc.ready: | |
vc.resume() | |
discard await discord.api.sendMessage(m.channel_id, "Sound resumed.") | |
of "leave": | |
if not connected: | |
discard await discord.api.sendMessage(m.channel_id, "I'm not connected in voice channel.") | |
await s.voiceStateUpdate(m.guild_id.get, channel_id = none string) | |
connected = false | |
waitFor discord.startSession( | |
# compress = true, | |
autoreconnect = true, | |
# gateway_version = 6, | |
large_message_threshold = 2, | |
gateway_intents = { | |
giGuildMembers, | |
giGuilds, | |
giGuildMessages, | |
# giGuildPresences, | |
giGuildVoiceStates, | |
giMessageContent | |
}, | |
cache_users = false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment