beansd
This commit is contained in:
parent
e3f04b2bd4
commit
ac6cfac0d3
@ -13,6 +13,7 @@ intents = discord.Intents.all()
|
|||||||
bot = bridge.Bot(intents=intents,command_prefix=".")
|
bot = bridge.Bot(intents=intents,command_prefix=".")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read("config/config.conf")
|
config.read("config/config.conf")
|
||||||
|
bot.config = config
|
||||||
bot.db = MongoClient(config["mongodb"]["host"],int(config["mongodb"]["port"]),username=config["mongodb"]["username"],password=config["mongodb"]["password"])['data']
|
bot.db = MongoClient(config["mongodb"]["host"],int(config["mongodb"]["port"]),username=config["mongodb"]["username"],password=config["mongodb"]["password"])['data']
|
||||||
bot.version = "2.0.0"
|
bot.version = "2.0.0"
|
||||||
|
|
||||||
|
|||||||
107
py/cogs/voice.py
107
py/cogs/voice.py
@ -1,12 +1,19 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import bridge, commands
|
from discord.ext import bridge, commands
|
||||||
from yt_dlp import YoutubeDL
|
import wavelink
|
||||||
from bin.storage import Config
|
from bin.storage import Config
|
||||||
|
|
||||||
class Voice(commands.Cog):
|
class Voice(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
await wavelink.NodePool.create_node(bot=self.bot,
|
||||||
|
host=self.bot.config["wavelink"]["host"],
|
||||||
|
port=self.bot.config["wavelink"]["port"],
|
||||||
|
password=self.bot.config["wavelink"]["password"],)
|
||||||
|
|
||||||
def qhandler(error=None,self=None, ctx=None, st=None):
|
def qhandler(error=None,self=None, ctx=None, st=None):
|
||||||
print("test")
|
print("test")
|
||||||
queue = (st.read("voice", "queue")).split("/./")
|
queue = (st.read("voice", "queue")).split("/./")
|
||||||
@ -43,34 +50,36 @@ class Voice(commands.Cog):
|
|||||||
await ctx.voice_client.disconnect()
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
@bridge.bridge_command(aliases=["p"])
|
@bridge.bridge_command(aliases=["p"])
|
||||||
async def play(self, ctx, *, video: str=""):
|
async def play(self, ctx, *, link: str):
|
||||||
await ctx.defer()
|
# await ctx.defer()
|
||||||
args = video.split(" ")
|
# args = video.split(" ")
|
||||||
providedchannel = False
|
# providedchannel = False
|
||||||
channel = ""
|
channel = ""
|
||||||
for arg in range(len(args)-1):
|
# for arg in range(len(args)-1):
|
||||||
if args[arg] == "-channel" or args[arg] == "-c":
|
# if args[arg] == "-channel" or args[arg] == "-c":
|
||||||
channel = self.bot.get_channel(discord.utils.get(ctx.guild.channels, name=args.pop(arg+1)).id)
|
# channel = self.bot.get_channel(discord.utils.get(ctx.guild.channels, name=args.pop(arg+1)).id)
|
||||||
print(type(channel))
|
# print(type(channel))
|
||||||
print(channel)
|
# print(channel)
|
||||||
args.pop(arg)
|
# args.pop(arg)
|
||||||
providedchannel = True
|
# providedchannel = True
|
||||||
break
|
# break
|
||||||
else:
|
# else:
|
||||||
channel = ctx.author.voice.channel
|
# channel = ctx.author.voice.channel
|
||||||
|
|
||||||
link = " ".join(args)
|
# link = " ".join(args)
|
||||||
|
|
||||||
if providedchannel and ctx.author.guild_permissions.administrator == False:
|
# if providedchannel and ctx.author.guild_permissions.administrator == False:
|
||||||
await ctx.respond("You do not have permission to specify a channel")
|
# await ctx.respond("You do not have permission to specify a channel")
|
||||||
return
|
# return
|
||||||
|
|
||||||
if ctx.author.voice is None and channel == "":
|
if ctx.author.voice is None and channel == "":
|
||||||
await ctx.respond("You are not in a voice channel, to specify a channel use `play <link> -channel <channel>`")
|
await ctx.respond("You are not in a voice channel, to specify a channel use `play <link> -channel <channel>`")
|
||||||
return
|
return
|
||||||
|
|
||||||
if ctx.voice_client is None:
|
if ctx.voice_client is None:
|
||||||
await channel.connect()
|
if channel == "":
|
||||||
|
channel = ctx.author.voice.channel
|
||||||
|
vc = await channel.connect(cls=wavelink.Player)
|
||||||
|
|
||||||
if link == "" and ctx.voice_client.is_paused():
|
if link == "" and ctx.voice_client.is_paused():
|
||||||
ctx.voice_client.resume()
|
ctx.voice_client.resume()
|
||||||
@ -78,46 +87,21 @@ class Voice(commands.Cog):
|
|||||||
|
|
||||||
if ctx.voice_client.is_paused():
|
if ctx.voice_client.is_paused():
|
||||||
ctx.voice_client.resume()
|
ctx.voice_client.resume()
|
||||||
|
await vc.play(await wavelink.YouTubeTrack.search(link,return_first=True))
|
||||||
ffmpeg_options = {
|
await ctx.respond(f"Now playing: {link}")
|
||||||
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
# ffmpeg_options = {
|
||||||
'options': '-vn'
|
# 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||||
}
|
# 'options': '-vn'
|
||||||
ytdl_format_options = {
|
# }
|
||||||
'format': 'bestaudio/best',
|
# if not ctx.voice_client.is_playing():
|
||||||
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
|
# ctx.voice_client.play(discord.FFmpegPCMAudio(video_url, **ffmpeg_options), after=self.qhandler(self=self, ctx=ctx, st=st))
|
||||||
'restrictfilenames': True,
|
# await ctx.respond(f"Now playing: {video_title}")
|
||||||
'noplaylist': True,
|
# else:
|
||||||
'nocheckcertificate': True,
|
# print("Added to queue")
|
||||||
'ignoreerrors': False,
|
# queue = st.read("voice", "queue").split("/./")
|
||||||
'logtostderr': False,
|
# queue.append(info_dict.get("url",None))
|
||||||
'quiet': True,
|
# st.write("voice", "queue", "/./".join(queue))
|
||||||
'no_warnings': True,
|
# await ctx.respond(f"Added to queue: {video_title}")
|
||||||
'default_search': 'auto',
|
|
||||||
'source_address': '0.0.0.0',
|
|
||||||
}
|
|
||||||
|
|
||||||
with YoutubeDL(ytdl_format_options) as ydl:
|
|
||||||
st = Config(ctx.guild.id, self.bot.db)
|
|
||||||
if link.startswith("https://"):
|
|
||||||
info_dict = ydl.extract_info(link, download=False)
|
|
||||||
video_url = info_dict.get("url", None)
|
|
||||||
video_id = info_dict.get("id", None)
|
|
||||||
video_title = info_dict.get('title', None)
|
|
||||||
else:
|
|
||||||
info_dict = ydl.extract_info(f"ytsearch:{link}", download=False)["entries"][0]
|
|
||||||
video_url = info_dict.get("url", None)
|
|
||||||
video_id = info_dict.get("id", None)
|
|
||||||
video_title = info_dict.get('title', None)
|
|
||||||
if not ctx.voice_client.is_playing():
|
|
||||||
ctx.voice_client.play(discord.FFmpegPCMAudio(video_url, **ffmpeg_options), after=self.qhandler(self=self, ctx=ctx, st=st))
|
|
||||||
await ctx.respond(f"Now playing: {video_title}")
|
|
||||||
else:
|
|
||||||
print("Added to queue")
|
|
||||||
queue = st.read("voice", "queue").split("/./")
|
|
||||||
queue.append(info_dict.get("url",None))
|
|
||||||
st.write("voice", "queue", "/./".join(queue))
|
|
||||||
await ctx.respond(f"Added to queue: {video_title}")
|
|
||||||
|
|
||||||
@bridge.bridge_command(aliases=["stop"])
|
@bridge.bridge_command(aliases=["stop"])
|
||||||
async def pause(self, ctx):
|
async def pause(self, ctx):
|
||||||
@ -125,7 +109,7 @@ class Voice(commands.Cog):
|
|||||||
if ctx.voice_client is None:
|
if ctx.voice_client is None:
|
||||||
await ctx.respond("I am not in a voice channel")
|
await ctx.respond("I am not in a voice channel")
|
||||||
else:
|
else:
|
||||||
ctx.voice_client.pause()
|
await ctx.voice_client.pause()
|
||||||
await ctx.respond("Paused")
|
await ctx.respond("Paused")
|
||||||
|
|
||||||
@bridge.bridge_command(alias=["next", "n","s"])
|
@bridge.bridge_command(alias=["next", "n","s"])
|
||||||
@ -140,4 +124,3 @@ class Voice(commands.Cog):
|
|||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Voice(bot))
|
bot.add_cog(Voice(bot))
|
||||||
|
|
||||||
|
|
||||||
143
py/cogs/voice_old.py
Normal file
143
py/cogs/voice_old.py
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
import discord
|
||||||
|
from discord.ext import bridge, commands
|
||||||
|
from yt_dlp import YoutubeDL
|
||||||
|
from bin.storage import Config
|
||||||
|
|
||||||
|
class Voice(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
def qhandler(error=None,self=None, ctx=None, st=None):
|
||||||
|
print("test")
|
||||||
|
queue = (st.read("voice", "queue")).split("/./")
|
||||||
|
try:
|
||||||
|
queue.pop(0)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
st.write("voice", "queue", "/./".join(queue))
|
||||||
|
ffmpeg_options = {
|
||||||
|
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||||
|
'options': '-vn'
|
||||||
|
}
|
||||||
|
if len(queue) > 0:
|
||||||
|
ctx.voice_client.play(discord.FFmpegPCMAudio(queue[0]), **ffmpeg_options, after=self.qhandler(self, ctx))
|
||||||
|
ctx.respond(f"Now playing: {queue[0]}")
|
||||||
|
|
||||||
|
@bridge.bridge_command(alises=["j"])
|
||||||
|
async def join(self, ctx):
|
||||||
|
await ctx.defer()
|
||||||
|
if ctx.author.voice is None:
|
||||||
|
await ctx.respond("You are not in a voice channel")
|
||||||
|
else:
|
||||||
|
channel = ctx.author.voice.channel
|
||||||
|
await channel.connect()
|
||||||
|
|
||||||
|
@bridge.bridge_command(alises=["l"])
|
||||||
|
async def leave(self, ctx):
|
||||||
|
await ctx.defer()
|
||||||
|
st = Config(ctx.guild.id, self.bot.db)
|
||||||
|
st.write("voice", "queue", "")
|
||||||
|
if ctx.voice_client is None:
|
||||||
|
await ctx.respond("I am not in a voice channel")
|
||||||
|
else:
|
||||||
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
|
@bridge.bridge_command(aliases=["p"])
|
||||||
|
async def play(self, ctx, *, video: str=""):
|
||||||
|
await ctx.defer()
|
||||||
|
args = video.split(" ")
|
||||||
|
providedchannel = False
|
||||||
|
channel = ""
|
||||||
|
for arg in range(len(args)-1):
|
||||||
|
if args[arg] == "-channel" or args[arg] == "-c":
|
||||||
|
channel = self.bot.get_channel(discord.utils.get(ctx.guild.channels, name=args.pop(arg+1)).id)
|
||||||
|
print(type(channel))
|
||||||
|
print(channel)
|
||||||
|
args.pop(arg)
|
||||||
|
providedchannel = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
channel = ctx.author.voice.channel
|
||||||
|
|
||||||
|
link = " ".join(args)
|
||||||
|
|
||||||
|
if providedchannel and ctx.author.guild_permissions.administrator == False:
|
||||||
|
await ctx.respond("You do not have permission to specify a channel")
|
||||||
|
return
|
||||||
|
|
||||||
|
if ctx.author.voice is None and channel == "":
|
||||||
|
await ctx.respond("You are not in a voice channel, to specify a channel use `play <link> -channel <channel>`")
|
||||||
|
return
|
||||||
|
|
||||||
|
if ctx.voice_client is None:
|
||||||
|
await channel.connect()
|
||||||
|
|
||||||
|
if link == "" and ctx.voice_client.is_paused():
|
||||||
|
ctx.voice_client.resume()
|
||||||
|
return
|
||||||
|
|
||||||
|
if ctx.voice_client.is_paused():
|
||||||
|
ctx.voice_client.resume()
|
||||||
|
|
||||||
|
ffmpeg_options = {
|
||||||
|
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||||
|
'options': '-vn'
|
||||||
|
}
|
||||||
|
ytdl_format_options = {
|
||||||
|
'format': 'bestaudio/best',
|
||||||
|
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
|
||||||
|
'restrictfilenames': True,
|
||||||
|
'noplaylist': True,
|
||||||
|
'nocheckcertificate': True,
|
||||||
|
'ignoreerrors': False,
|
||||||
|
'logtostderr': False,
|
||||||
|
'quiet': True,
|
||||||
|
'no_warnings': True,
|
||||||
|
'default_search': 'auto',
|
||||||
|
'source_address': '0.0.0.0',
|
||||||
|
}
|
||||||
|
|
||||||
|
with YoutubeDL(ytdl_format_options) as ydl:
|
||||||
|
st = Config(ctx.guild.id, self.bot.db)
|
||||||
|
if link.startswith("https://"):
|
||||||
|
info_dict = ydl.extract_info(link, download=False)
|
||||||
|
video_url = info_dict.get("url", None)
|
||||||
|
video_id = info_dict.get("id", None)
|
||||||
|
video_title = info_dict.get('title', None)
|
||||||
|
else:
|
||||||
|
info_dict = ydl.extract_info(f"ytsearch:{link}", download=False)["entries"][0]
|
||||||
|
video_url = info_dict.get("url", None)
|
||||||
|
video_id = info_dict.get("id", None)
|
||||||
|
video_title = info_dict.get('title', None)
|
||||||
|
if not ctx.voice_client.is_playing():
|
||||||
|
ctx.voice_client.play(discord.FFmpegPCMAudio(video_url, **ffmpeg_options), after=self.qhandler(self=self, ctx=ctx, st=st))
|
||||||
|
await ctx.respond(f"Now playing: {video_title}")
|
||||||
|
else:
|
||||||
|
print("Added to queue")
|
||||||
|
queue = st.read("voice", "queue").split("/./")
|
||||||
|
queue.append(info_dict.get("url",None))
|
||||||
|
st.write("voice", "queue", "/./".join(queue))
|
||||||
|
await ctx.respond(f"Added to queue: {video_title}")
|
||||||
|
|
||||||
|
@bridge.bridge_command(aliases=["stop"])
|
||||||
|
async def pause(self, ctx):
|
||||||
|
await ctx.defer()
|
||||||
|
if ctx.voice_client is None:
|
||||||
|
await ctx.respond("I am not in a voice channel")
|
||||||
|
else:
|
||||||
|
ctx.voice_client.pause()
|
||||||
|
await ctx.respond("Paused")
|
||||||
|
|
||||||
|
@bridge.bridge_command(alias=["next", "n","s"])
|
||||||
|
async def skip(self, ctx):
|
||||||
|
await ctx.defer()
|
||||||
|
if ctx.voice_client is None:
|
||||||
|
await ctx.respond("I am not in a voice channel")
|
||||||
|
else:
|
||||||
|
ctx.voice_client.stop()
|
||||||
|
await ctx.respond("Skipped")
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Voice(bot))
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user