mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-06 22:34:30 +01:00
What. The. Fuck
This commit is contained in:
1 parent
04f89ffea3
commit
a3d6deea54
4 files changed
+101
-67
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import codecs
|
||||
import discord
|
||||
import time
|
||||
@@ -9,85 +8,85 @@ from cogs.utils.settings import Settings
|
||||
|
||||
|
||||
initial_extension = [
|
||||
'cogs.cogs',
|
||||
'cogs.botsettings',
|
||||
'cogs.misc',
|
||||
'cogs.music'
|
||||
'cogs.cogs',
|
||||
'cogs.botsettings',
|
||||
'cogs.misc',
|
||||
'cogs.music'
|
||||
]
|
||||
|
||||
|
||||
with codecs.open("config.json", 'r', encoding='utf8') as f:
|
||||
config = json.load(f)
|
||||
config = json.load(f)
|
||||
|
||||
|
||||
def _get_prefix(bot, message):
|
||||
if not message.guild:
|
||||
return default_prefix
|
||||
prefixes = bot.settings.get_prefix(message.guild.id)
|
||||
return commands.when_mentioned_or(*prefixes)(bot, message)
|
||||
if not message.guild:
|
||||
return default_prefix
|
||||
prefixes = bot.settings.get_prefix(message.guild.id)
|
||||
return commands.when_mentioned_or(*prefixes)(bot, message)
|
||||
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=_get_prefix,
|
||||
description=config["description"])
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=_get_prefix,
|
||||
description=config["description"])
|
||||
|
||||
self.settings = Settings(**config)
|
||||
self.settings = Settings(**config)
|
||||
|
||||
for extension in initial_extension:
|
||||
try:
|
||||
self.load_extension(extension)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
for extension in initial_extension:
|
||||
try:
|
||||
self.load_extension(extension)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
async def on_command_error(self, ctx, err):
|
||||
if (isinstance(err, commands.MissingRequiredArgument) or
|
||||
isinstance(err, commands.BadArgument)):
|
||||
formatter = ctx.bot.formatter
|
||||
if ctx.invoked_subcommand is None:
|
||||
_help = await formatter.format_help_for(ctx, ctx.command)
|
||||
else:
|
||||
_help = await formatter.format_help_for(ctx,
|
||||
ctx.invoked_subcommand)
|
||||
# async def on_command_error(self, ctx, err):
|
||||
# if (isinstance(err, commands.MissingRequiredArgument) or
|
||||
# isinstance(err, commands.BadArgument)):
|
||||
# formatter = ctx.bot.formatter
|
||||
# if ctx.invoked_subcommand is None:
|
||||
# _help = await formatter.format_help_for(ctx, ctx.command)
|
||||
# else:
|
||||
# _help = await formatter.format_help_for(ctx,
|
||||
# ctx.invoked_subcommand)
|
||||
#
|
||||
# for message in _help:
|
||||
# await ctx.send(message)
|
||||
#
|
||||
# if isinstance(err, commands.CommandInvokeError):
|
||||
# pass
|
||||
#
|
||||
# elif isinstance(err, commands.NoPrivateMessage):
|
||||
# await ctx.send("Denne kommandoen er ikke tilgjengelig i DMs")
|
||||
#
|
||||
# elif isinstance(err, commands.CheckFailure):
|
||||
# pass
|
||||
#
|
||||
# elif isinstance(err, commands.CommandNotFound):
|
||||
# pass
|
||||
|
||||
for message in _help:
|
||||
await ctx.send(message)
|
||||
async def on_ready(self):
|
||||
if not hasattr(self, 'uptime'):
|
||||
self.uptime = time.time()
|
||||
|
||||
if isinstance(err, commands.CommandInvokeError):
|
||||
pass
|
||||
print(f'\nLogged in as: {self.user.name}' +
|
||||
f' in {len(self.guilds)} servers.')
|
||||
print(f'Version: {discord.__version__}\n')
|
||||
|
||||
elif isinstance(err, commands.NoPrivateMessage):
|
||||
await ctx.send("Denne kommandoen er ikke tilgjengelig i DMs")
|
||||
await self.change_presence(activity=discord.Game(type=0,
|
||||
name=config["playing"]),
|
||||
status=discord.Status.online)
|
||||
|
||||
elif isinstance(err, commands.CheckFailure):
|
||||
pass
|
||||
|
||||
elif isinstance(err, commands.CommandNotFound):
|
||||
pass
|
||||
|
||||
async def on_ready(self):
|
||||
if not hasattr(self, 'uptime'):
|
||||
self.uptime = time.time()
|
||||
|
||||
print(f'\nLogged in as: {self.user.name}' +
|
||||
f' in {len(self.guilds)} servers.')
|
||||
print(f'Version: {discord.__version__}\n')
|
||||
|
||||
await self.change_presence(activity=discord.Game(type=0,
|
||||
name=config["playing"]),
|
||||
status=discord.Status.online)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
super().run(config["token"], reconnect=True)
|
||||
except Exception as e:
|
||||
print('ifkn', e)
|
||||
def run(self):
|
||||
try:
|
||||
super().run(config["token"], reconnect=True)
|
||||
except Exception as e:
|
||||
print('ifkn', e)
|
||||
|
||||
|
||||
def run_bot():
|
||||
bot = Bot()
|
||||
bot.run()
|
||||
bot = Bot()
|
||||
bot.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_bot()
|
||||
run_bot()
|
||||
+4
-4
@@ -51,7 +51,7 @@ class Music:
|
||||
|
||||
if isinstance(event, lavalink.Events.TrackStartEvent):
|
||||
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)
|
||||
thumbnail_url = await RoxUtils.ThumbNailer.identify(self, event.player.current.identifier, event.player.current.uri)
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
await channel.send(embed=embed)
|
||||
@@ -89,7 +89,7 @@ class Music:
|
||||
track = results['tracks'][0]
|
||||
embed.title = 'Track Enqueued'
|
||||
print(track)
|
||||
thumbnail_url = RoxUtils.thumbnailer(self, track['info']['identifier'], track['info']['uri'])
|
||||
thumbnail_url = await RoxUtils.ThumbNailer.identify(self, track['info']['identifier'], track['info']['uri'])
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
|
||||
@@ -218,7 +218,7 @@ 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)
|
||||
thumbnail_url = await RoxUtils.ThumbNailer.identify(self, player.current.identifier, player.current.uri)
|
||||
if thumbnail_url:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
|
||||
@@ -377,7 +377,7 @@ class Music:
|
||||
track_ = tracks[track_num]
|
||||
await self.send_to_play(ctx, track_)
|
||||
embed.title = "Song sent to queue"
|
||||
thumb_url = RoxUtils.thumbnailer(self, track_['info']['identifier'],track_['info']['uri'])
|
||||
thumb_url = RoxUtils.ThumbNailer.identify(self, track_['info']['identifier'],track_['info']['uri'])
|
||||
if thumb_url:
|
||||
embed.set_thumbnail(url=thumb_url)
|
||||
embed.description = f'[{track_["info"]["title"]}]({track_["info"]["uri"]})'
|
||||
|
||||
+36
-1
@@ -1,6 +1,41 @@
|
||||
import requests
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from bs4 import BeautifulSoup as BS
|
||||
|
||||
|
||||
class ThumbNailer(object):
|
||||
|
||||
def __init__(self):
|
||||
self.url = self
|
||||
|
||||
async def connection(self, url):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, timeout=30) as response:
|
||||
assert response.status == 200
|
||||
html = await response.read()
|
||||
return ThumbNailer.__parse_result(html)
|
||||
|
||||
def __parse_result(html):
|
||||
try:
|
||||
soup = BS(html, 'html.parser')
|
||||
img = soup.find("meta", property="twitter:image")["content"]
|
||||
return img
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
async def identify(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 = await ThumbNailer.connection(ThumbNailer, url=uri)
|
||||
return thumbnail_url
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def thumbnailer(self, identifier, uri):
|
||||
thumbnail_url = ""
|
||||
if "youtube" in uri:
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
git+https://github.com/Rapptz/discord.py@rewrite
|
||||
asyncio
|
||||
lavalink
|
||||
requests
|
||||
bs4
|
||||
bs4
|
||||
aiohttp
|
||||
Reference in new issue
Block a user