working on voice
This commit is contained in:
parent
12a219eb3a
commit
94ab3c716b
@ -10,7 +10,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
#setup
|
||||
intents = discord.Intents.all()
|
||||
bot = bridge.AutoShardedBot(shard_count=4,shard_ids=[2,3],intents=intents,command_prefix=".")
|
||||
bot = bridge.Bot(intents=intents,command_prefix=".")
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config/config.conf")
|
||||
bot.db = MongoClient(config["mongodb"]["host"],int(config["mongodb"]["port"]),username=config["mongodb"]["username"],password=config["mongodb"]["password"])['data']
|
||||
@ -20,7 +20,8 @@ bot.load_extension("cogs.counting")
|
||||
bot.load_extension("cogs.misc")
|
||||
bot.load_extension("cogs.triggers")
|
||||
bot.load_extension("cogs.dad")
|
||||
bot.load_extension("cogs.quotequeue")
|
||||
bot.load_extension("cogs.voice")
|
||||
#bot.load_extension("cogs.quotequeue")
|
||||
|
||||
|
||||
#logging
|
||||
|
||||
@ -2,25 +2,28 @@ import discord
|
||||
from discord.ext import commands, tasks
|
||||
|
||||
import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from bin.storage import Config
|
||||
|
||||
|
||||
times = [datetime.time(12,0,tzinfo=ZoneInfo("America/Denver"))]
|
||||
|
||||
class Quotequeue(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.db = bot.db
|
||||
self.quotequeue.start()
|
||||
self.quotetime.start()
|
||||
print(self.quotetime.next_iteration)
|
||||
|
||||
@tasks.loop(seconds=5)
|
||||
async def quotequeue(self):
|
||||
@tasks.loop(time=times)
|
||||
async def quotetime(self):
|
||||
channel = self.bot.get_channel(1004178748205187086)
|
||||
await channel.send("test")
|
||||
|
||||
@quotequeue.before_loop
|
||||
async def before_quotequeue(self):
|
||||
@quotetime.before_loop
|
||||
async def before_quotetime(self):
|
||||
await self.bot.wait_until_ready()
|
||||
print(self.quotetime.next_iteration)
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Quotequeue(bot))
|
||||
|
||||
70
py/cogs/voice.py
Normal file
70
py/cogs/voice.py
Normal file
@ -0,0 +1,70 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from yt_dlp import YoutubeDL
|
||||
from bin.storage import Config
|
||||
|
||||
class Voice(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.queue = []
|
||||
|
||||
def player(self, ctx):
|
||||
print(self.queue)
|
||||
if len(self.queue) == 0:
|
||||
return
|
||||
self.queue.pop(0)
|
||||
ffmpeg_options = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
|
||||
ctx.voice_client.play(discord.FFmpegPCMAudio(self.queue[0], **ffmpeg_options), after=Voice.player(self, ctx))
|
||||
|
||||
|
||||
@commands.command()
|
||||
async def join(self, ctx):
|
||||
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()
|
||||
|
||||
@commands.command()
|
||||
async def leave(self, ctx):
|
||||
if ctx.voice_client is None:
|
||||
await ctx.respond("I am not in a voice channel")
|
||||
else:
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
@commands.command()
|
||||
async def play(self, ctx, link):
|
||||
if ctx.author.voice is None:
|
||||
await ctx.respond("You are not in a voice channel")
|
||||
if ctx.voice_client is None:
|
||||
channel = ctx.author.voice.channel
|
||||
await channel.connect()
|
||||
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:
|
||||
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)
|
||||
self.queue.append(video_url)
|
||||
if not ctx.voice_client.is_playing():
|
||||
ctx.voice_client.play(discord.FFmpegPCMAudio(self.queue[0], **ffmpeg_options), after=Voice.player(self, ctx))
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Voice(bot))
|
||||
Loading…
Reference in New Issue
Block a user