mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-07 06:44:29 +01:00
.gitignore
added IDE and tests folder bot.py PEP8 cogs/music.py added thumbnails to now playing, and when song is added to queue cogs/utils/RoxUtils.py added function to fetch thumbnail url youtube = OK soundcloud = OK requirements.txt added bs4, and requests requirements
This commit is contained in:
1 parent
d35304715d
commit
7cf4111925
5 files changed
+37
-6
No files matched your search
@@ -2,6 +2,8 @@ config.json
|
||||
data/
|
||||
lavalink/
|
||||
lavasettings.py
|
||||
.tests/
|
||||
.idea/
|
||||
|
||||
#Python crap
|
||||
|
||||
|
||||
@@ -88,5 +88,6 @@ def run_bot():
|
||||
bot = Bot()
|
||||
bot.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_bot()
|
||||
+18
-5
@@ -10,6 +10,8 @@ import logging
|
||||
import math
|
||||
import re
|
||||
|
||||
from cogs.utils import RoxUtils
|
||||
|
||||
import discord
|
||||
import lavalink
|
||||
from discord.ext import commands
|
||||
@@ -46,10 +48,11 @@ class Music:
|
||||
return
|
||||
|
||||
if isinstance(event, lavalink.Events.TrackStartEvent):
|
||||
await channel.send(embed=discord.Embed(title='Now playing:',
|
||||
description=event.track.title,
|
||||
color=discord.Color.blurple()))
|
||||
|
||||
embed = discord.Embed(title='Now playing:', description=event.track.title, color=discord.Color.blurple())
|
||||
thumbnail_url = RoxUtils.thumbnailer(self, event.player.current.identifier, event.player.current.uri)
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
await channel.send(embed=embed)
|
||||
elif isinstance(event, lavalink.Events.QueueEndEvent):
|
||||
await channel.send('Queue ended! Why not queue more songs?')
|
||||
|
||||
@@ -83,6 +86,11 @@ class Music:
|
||||
else:
|
||||
track = results['tracks'][0]
|
||||
embed.title = 'Track Enqueued'
|
||||
|
||||
thumbnail_url = RoxUtils.thumbnailer(self, track['info']['identifier'], track['info']['uri'])
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
|
||||
embed.description = f'[{track["info"]["title"]}]({track["info"]["uri"]})'
|
||||
await ctx.send(embed=embed)
|
||||
player.add(requester=ctx.author.id, track=track)
|
||||
@@ -207,6 +215,11 @@ class Music:
|
||||
|
||||
embed = discord.Embed(color=discord.Color.blurple(),
|
||||
title='Now Playing', description=song)
|
||||
|
||||
thumbnail_url = RoxUtils.thumbnailer(self, player.current.identifier, player.current.uri)
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name='queue', aliases=['q'])
|
||||
@@ -369,4 +382,4 @@ class Music:
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Music(bot))
|
||||
bot.add_cog(Music(bot))
|
||||
@@ -0,0 +1,13 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup as BS
|
||||
|
||||
def thumbnailer(self, identifier, uri):
|
||||
thumbnail_url = ""
|
||||
if "youtube" in uri:
|
||||
thumbnail_url = f"https://img.youtube.com/vi/{identifier}/0.jpg"
|
||||
return thumbnail_url
|
||||
elif "soundcloud" in uri:
|
||||
thumbnail_url = BS(requests.get(uri).text, "html.parser").find("meta", property="twitter:image")["content"]
|
||||
return thumbnail_url
|
||||
else:
|
||||
return None
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
git+https://github.com/Rapptz/discord.py@rewrite
|
||||
asyncio
|
||||
lavalink
|
||||
lavalink
|
||||
requests
|
||||
bs4
|
||||
Reference in new issue
Block a user