Browse Source

improved now playing formatting.

tags/v1.6.0
Roxie Gibson 6 years ago
parent
commit
1e13e6ff25
3 changed files with 36 additions and 20 deletions
  1. +7
    -1
      README.md
  2. +28
    -18
      Roxbot/cogs/voice.py
  3. +1
    -1
      Roxbot/load_config.py

+ 7
- 1
README.md View File

@@ -2,7 +2,7 @@

[![MIT](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![Python](https://img.shields.io/badge/Python-3.5%2B-blue.svg?style=flat-square)](https://github.com/RainbowDinoaur/roxbot/)
[![Say Thanks](https://img.shields.io/badge/say-thanks-ff69b4.svg?style=flat-square)](https://saythanks.io/to/Roxxers)
[![Say Thanks](https://img.shields.io/badge/say-thanks-ff69b4.svg?style=flat-square)](https://saythanks.io/to/roxxers)

RoxBot, A Discord Bot made by a filthy Mercy Main. Built with love (and discord.py)

@@ -15,6 +15,12 @@ _Coming Soon_

## Changelog

#### v1.6.1
###### Small changes
- `nowplaying` is now more handy and should display more info.
###### Hot Fixes
- Voice has received a number of hot fixes to make sure it works properally.

#### v1.6.0
###### New Features
- An entire music bot, right in Roxbot! New voice cog that allows for Roxbot to play audio in voice. A well functional discord music bot

+ 28
- 18
Roxbot/cogs/voice.py View File

@@ -1,6 +1,7 @@
import os
import asyncio
import discord
import datetime
import youtube_dl
from math import ceil
from discord.ext import commands
@@ -49,6 +50,7 @@ class YTDLSource(discord.PCMVolumeTransformer):
self.data = data
self.title = data.get('title')
self.uploader = data.get("uploader")
self.uploader_url = data.get("uploader_url")
self.url = data.get('url')
self.duration = data.get("duration")
self.host = data.get("extractor_key")
@@ -115,15 +117,18 @@ class Voice:
while ctx.voice_client.is_playing() or ctx.voice_client.is_paused():
await asyncio.sleep(sleep_for)
except AttributeError:
return # This is to stop any errors appearing if the bot suddenly leaves voice chat.
if self.playlist[ctx.guild.id]:
player = self.playlist[ctx.guild.id].pop(0)
if player.get("stream", False) is True:
command = self.stream
else:
command = self.play
await ctx.invoke(command, url=player, from_queue=True)
pass # This is to stop any errors appearing if the bot suddenly leaves voice chat.
self.now_playing[ctx.guild.id] = None
self.skip_votes[ctx.guild.id] = []
if self.playlist[ctx.guild.id] and ctx.voice_client:
if not ctx.voice_client.playing():
player = self.playlist[ctx.guild.id].pop(0)
if player.get("stream", False) is True:
command = self.stream
else:
command = self.play
await ctx.invoke(command, url=player, from_queue=True)


def _queue_song(self, ctx, video, stream):
"""Fuction to queue up a video into the playlist."""
@@ -132,6 +137,17 @@ class Voice:
self.playlist[ctx.guild.id].append(video)
return video

def _generate_np_embed(self, guild, playing_status):
# TODO: Clean this up as it does end up butchering the source object and why i even made it like it is. Maybe move it all back in that object later but atm im just trying to get it to work.
np = self.now_playing[guild.id]
title = "{0}: '{1.title}' from {1.host}".format(playing_status, np)
duration = datetime.timedelta(seconds=np.duration)

embed = discord.Embed(title=title, colour=0xDEADBF, url=np.webpage_url)
embed.description = "Uploaded by: [{0.uploader}]({0.uploader_url})\nURL: [Here]({0.webpage_url})\nDuration: {1}\nQueued by: {0.queued_by}".format(np, duration)
embed.set_image(url=np.thumbnail_url)
return embed

async def on_guild_join(self, guild):
"""Makes sure that when the bot joins a guild it won't need to reboot for the music bot to work."""
self.playlist[guild.id] = []
@@ -209,6 +225,8 @@ class Voice:

async with ctx.typing():
player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=stream, volume=self._volume[ctx.guild.id])
player.stream = stream
player.queued_by = ctx.author
self.now_playing[guild.id] = player
self.am_queuing[guild.id] = False

@@ -217,12 +235,7 @@ class Voice:
# Create task to deal with what to do when the video ends or is skipped and how to handle the queue
self.queue_logic[ctx.guild.id] = self.bot.loop.create_task(self._queue_logic(ctx))

embed = discord.Embed(
title="Now playing: '{0.title}' from {0.host}".format(player),
description= "Uploaded by: {0.uploader}\nURL: {0.webpage_url}".format(player),
colour=0xDEADBF
)
embed.set_image(url=player.thumbnail_url)
embed = self._generate_np_embed(ctx.guild, "Now Playing")
await ctx.send(embed=embed)
else:
# Queue the song as there is already a song playing or paused.
@@ -349,10 +362,7 @@ class Voice:
x = "Paused"
else:
x = "Now Playing"
title = "{0}: '{1.title}' from {1.host}".format(x, np)
embed = discord.Embed(title=title, colour=0xDEADBF)
embed.description = "Uploaded by: {0.uploader}\nURL: {0.webpage_url}".format(np)
embed.set_image(url=np.thumbnail_url)
embed = self._generate_np_embed(ctx.guild, x)
return await ctx.send(embed=embed)

@commands.command()

+ 1
- 1
Roxbot/load_config.py View File

@@ -16,7 +16,7 @@ __description__ = """RoxBot, A Discord Bot made by a filthy Mercy Main. Built wi
[Found a bug or need to report an issue? Report it here](https://github.com/RainbowRoxxers/roxbot/issues/new)
[Say Thanks](https://saythanks.io/to/Roxxers)"""
__author__ = "Roxanne Gibson"
__version__ = "1.6.0"
__version__ = "1.6.1"
embedcolour = 0xDEADBF

# IF YOU ARE TESTING OR NOT IN THE GSS DISCORD, REMOVE "cogs.gss" FROM THE LIST

Loading…
Cancel
Save