Merge branch 'rewrite' of https://github.com/Phxntxm/Bonfire into rewrite
This commit is contained in:
commit
893673aa94
|
@ -226,7 +226,7 @@ class Administration:
|
||||||
server_settings = await utils.get_content('server_settings', key)
|
server_settings = await utils.get_content('server_settings', key)
|
||||||
channel = str(ctx.message.channel.id)
|
channel = str(ctx.message.channel.id)
|
||||||
try:
|
try:
|
||||||
channels = server_settings['nsfw_channels']
|
channels = server_settings.get('nsfw_channels', None)
|
||||||
if channel in channels:
|
if channel in channels:
|
||||||
channels.remove(channel)
|
channels.remove(channel)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
class Images:
|
class Images:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -29,11 +30,10 @@ class Images:
|
||||||
return
|
return
|
||||||
|
|
||||||
image = await utils.download_image(filename)
|
image = await utils.download_image(filename)
|
||||||
filename = re.search('.*\/i\/(.*)', filename).group(1)
|
filename = re.search('.*/i/(.*)', filename).group(1)
|
||||||
f = discord.File(image, filename=filename)
|
f = discord.File(image, filename=filename)
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(aliases=['dog', 'rd'])
|
@commands.command(aliases=['dog', 'rd'])
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def doggo(self, ctx):
|
async def doggo(self, ctx):
|
||||||
|
@ -88,8 +88,11 @@ class Images:
|
||||||
if filedata is None:
|
if filedata is None:
|
||||||
await ctx.send(url)
|
await ctx.send(url)
|
||||||
else:
|
else:
|
||||||
f = discord.File(filedata, filename=filename)
|
try:
|
||||||
await ctx.send(file=f)
|
f = discord.File(filedata, filename=filename)
|
||||||
|
await ctx.send(file=f)
|
||||||
|
except discord.HTTPException:
|
||||||
|
await ctx.send("Sorry but that avatar is too large for me to send!")
|
||||||
else:
|
else:
|
||||||
await ctx.send(url)
|
await ctx.send(url)
|
||||||
|
|
||||||
|
@ -149,7 +152,7 @@ class Images:
|
||||||
|
|
||||||
# Get the image link from the now random page'd and random result from that page
|
# Get the image link from the now random page'd and random result from that page
|
||||||
index = random.SystemRandom().randint(0, len(results) - 1)
|
index = random.SystemRandom().randint(0, len(results) - 1)
|
||||||
#image_link = 'https://derpibooru.org/{}'.format(results[index]['id'])
|
# image_link = 'https://derpibooru.org/{}'.format(results[index]['id'])
|
||||||
image_link = 'https:{}'.format(results[index]['image'])
|
image_link = 'https:{}'.format(results[index]['image'])
|
||||||
else:
|
else:
|
||||||
await ctx.send("No results with that search term, {0}!".format(ctx.message.author.mention))
|
await ctx.send("No results with that search term, {0}!".format(ctx.message.author.mention))
|
||||||
|
@ -205,5 +208,6 @@ class Images:
|
||||||
await ctx.send("No results with that tag {}".format(ctx.message.author.mention))
|
await ctx.send("No results with that tag {}".format(ctx.message.author.mention))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Images(bot))
|
bot.add_cog(Images(bot))
|
||||||
|
|
|
@ -3,9 +3,8 @@ from discord.ext import commands
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import re
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import rethinkdb as r
|
|
||||||
|
|
||||||
class Moderation:
|
class Moderation:
|
||||||
"""Commands that can be used by a or an admin, depending on the command"""
|
"""Commands that can be used by a or an admin, depending on the command"""
|
||||||
|
@ -13,8 +12,6 @@ class Moderation:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@utils.custom_perms(kick_members=True)
|
@utils.custom_perms(kick_members=True)
|
||||||
|
|
|
@ -8,7 +8,6 @@ from . import utils
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
@ -60,7 +59,6 @@ class VoiceState:
|
||||||
self.current = None
|
self.current = None
|
||||||
|
|
||||||
async def audio_player_task(self):
|
async def audio_player_task(self):
|
||||||
fmt = ""
|
|
||||||
while True:
|
while True:
|
||||||
if self.playing:
|
if self.playing:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
@ -81,12 +79,11 @@ class VoiceState:
|
||||||
continue
|
continue
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except:
|
||||||
await song.channel.send("Failed to download {}!".format(song.title))
|
await song.channel.send("Failed to download {}!".format(song.title))
|
||||||
log.error(traceback.format_exc())
|
log.error(traceback.format_exc())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
source = FFmpegPCMAudio(
|
source = FFmpegPCMAudio(
|
||||||
self.current.filename,
|
self.current.filename,
|
||||||
before_options='-nostdin',
|
before_options='-nostdin',
|
||||||
|
@ -251,7 +248,8 @@ class Music:
|
||||||
pass
|
pass
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
||||||
async def on_voice_state_update(self, member, before, after):
|
# noinspection PyUnusedLocal
|
||||||
|
async def on_voice_state_update(self, _, __, after):
|
||||||
if after is None or after.channel is None:
|
if after is None or after.channel is None:
|
||||||
return
|
return
|
||||||
state = self.voice_states.get(after.channel.guild.id)
|
state = self.voice_states.get(after.channel.guild.id)
|
||||||
|
@ -266,6 +264,51 @@ class Music:
|
||||||
entry, _ = await state.songs.add_entry(song, ctx)
|
entry, _ = await state.songs.add_entry(song, ctx)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
async def join_channel(self, channel):
|
||||||
|
state = self.voice_states.get(channel.guild.id)
|
||||||
|
log.info("Joining channel {} in guild {}".format(channel.id, channel.guild.id))
|
||||||
|
|
||||||
|
# Send a message letting the channel know we are attempting to join
|
||||||
|
try:
|
||||||
|
msg = await channel.send("Trying to join channel {}...".format(channel.name))
|
||||||
|
except discord.Forbidden:
|
||||||
|
msg = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# If we're already connected, try moving to the channel
|
||||||
|
if state and state.voice and state.voice.channel:
|
||||||
|
await state.voice.move_to(channel)
|
||||||
|
# Otherwise, try connecting
|
||||||
|
else:
|
||||||
|
await channel.connect()
|
||||||
|
|
||||||
|
# If we have connnected, create our voice state
|
||||||
|
self.voice_states[channel.guild.id] = VoiceState(channel.guild, self.bot)
|
||||||
|
|
||||||
|
# If we can send messages, edit it to let the channel know we have succesfully joined
|
||||||
|
if msg:
|
||||||
|
await msg.edit(content="Ready to play audio in channel {}".format(channel.name))
|
||||||
|
return True
|
||||||
|
# If we time out trying to join, just let them know and return False
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
if msg:
|
||||||
|
await msg.edit(content="Sorry, but I couldn't connect right now! Please try again later")
|
||||||
|
return False
|
||||||
|
# Theoretically this should never happen, however in rare cirumstances it does
|
||||||
|
# This error arises when we are already in a channel and don't use "move"
|
||||||
|
# We already checked if that existed above though, so this means the voice connection got stuck somewhere
|
||||||
|
except discord.ClientException:
|
||||||
|
if channel.guild.voice_client:
|
||||||
|
# Force a disconnection
|
||||||
|
await channel.guild.voice_client.disconnect(force=True)
|
||||||
|
# Log this so we can track it
|
||||||
|
log.warning(
|
||||||
|
"Force cleared voice connection on guild {} after being stuck "
|
||||||
|
"between connected/not connected".format(channel.guild.id))
|
||||||
|
# Let them know what happened
|
||||||
|
await channel.send("Sorry but I couldn't connect...try again?")
|
||||||
|
return False
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
|
@ -308,30 +351,12 @@ class Music:
|
||||||
|
|
||||||
perms = channel.permissions_for(ctx.message.guild.me)
|
perms = channel.permissions_for(ctx.message.guild.me)
|
||||||
|
|
||||||
log.info("Joining channel {} in guild {}".format(channel.id, ctx.message.guild.id))
|
|
||||||
|
|
||||||
if not perms.connect or not perms.speak or not perms.use_voice_activation:
|
if not perms.connect or not perms.speak or not perms.use_voice_activation:
|
||||||
await ctx.send("I do not have correct permissions in {}! Please turn on `connect`, `speak`, and `use "
|
await ctx.send("I do not have correct permissions in {}! Please turn on `connect`, `speak`, and `use "
|
||||||
"voice activation`".format(channel.name))
|
"voice activation`".format(channel.name))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
state = self.voice_states.get(ctx.message.guild.id)
|
return await self.join_channel(channel)
|
||||||
try:
|
|
||||||
if state and state.voice and state.voice.channel:
|
|
||||||
await state.voice.move_to(channel)
|
|
||||||
else:
|
|
||||||
await channel.connect()
|
|
||||||
self.voice_states[ctx.message.guild.id] = VoiceState(ctx.message.guild, self.bot)
|
|
||||||
return True
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
await ctx.send("Sorry, but I couldn't connect right now! Please try again later")
|
|
||||||
return False
|
|
||||||
except discord.ClientException:
|
|
||||||
if channel.guild.voice_client:
|
|
||||||
await channel.guild.voice_client.disconnect(force=True)
|
|
||||||
log.warning("Force cleared voice connection on guild {} after being stuck between connected/not connected".format(ctx.message.guild.id))
|
|
||||||
await ctx.send("Sorry but I couldn't connect...try again?")
|
|
||||||
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@ -349,7 +374,7 @@ class Music:
|
||||||
return
|
return
|
||||||
|
|
||||||
song = re.sub('[<>\[\]]', '', song)
|
song = re.sub('[<>\[\]]', '', song)
|
||||||
if len (song) == 11:
|
if len(song) == 11:
|
||||||
# Youtube-dl will attempt to things with the length of 11 as a video ID
|
# Youtube-dl will attempt to things with the length of 11 as a video ID
|
||||||
# If this is a search, this causes it to break
|
# If this is a search, this causes it to break
|
||||||
# Youtube will still succeed if this *is* an ID provided, if there's a . after
|
# Youtube will still succeed if this *is* an ID provided, if there's a . after
|
||||||
|
@ -384,7 +409,7 @@ class Music:
|
||||||
embed = entry.to_embed()
|
embed = entry.to_embed()
|
||||||
embed.title = "Enqueued song!"
|
embed.title = "Enqueued song!"
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
except discord.Forbidden:
|
except (discord.Forbidden, discord.HTTPException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
|
@ -395,7 +420,7 @@ class Music:
|
||||||
|
|
||||||
state = self.voice_states.get(ctx.message.guild.id)
|
state = self.voice_states.get(ctx.message.guild.id)
|
||||||
if value:
|
if value:
|
||||||
value = value / 100
|
value /= 100
|
||||||
if state is None or state.voice is None:
|
if state is None or state.voice is None:
|
||||||
await ctx.send("I need to be in a channel before my volume can be set")
|
await ctx.send("I need to be in a channel before my volume can be set")
|
||||||
elif value is None:
|
elif value is None:
|
||||||
|
@ -432,17 +457,17 @@ class Music:
|
||||||
This also clears the queue.
|
This also clears the queue.
|
||||||
"""
|
"""
|
||||||
state = self.voice_states.get(ctx.message.guild.id)
|
state = self.voice_states.get(ctx.message.guild.id)
|
||||||
|
voice = ctx.message.guild.voice_client
|
||||||
|
if voice:
|
||||||
|
voice.stop()
|
||||||
|
await voice.disconnect(force=True)
|
||||||
|
|
||||||
# Stop playing whatever song is playing.
|
if state:
|
||||||
if state and state.voice:
|
|
||||||
state.voice.stop()
|
|
||||||
|
|
||||||
state.songs.clear()
|
state.songs.clear()
|
||||||
|
|
||||||
# This will cancel the audio event we're using to loop through the queue
|
# This will cancel the audio event we're using to loop through the queue
|
||||||
# Then erase the voice_state entirely, and disconnect from the channel
|
# Then erase the voice_state entirely, and disconnect from the channel
|
||||||
state.audio_player.cancel()
|
state.audio_player.cancel()
|
||||||
await state.voice.disconnect()
|
|
||||||
try:
|
try:
|
||||||
del self.voice_states[ctx.message.guild.id]
|
del self.voice_states[ctx.message.guild.id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -502,8 +527,11 @@ class Music:
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def queuelength(self, ctx):
|
async def queuelength(self, ctx):
|
||||||
"""Prints the length of the queue"""
|
"""Prints the length of the queue"""
|
||||||
await ctx.send("There are a total of {} songs in the queue"
|
state = self.voice_states.get(ctx.message.guild.id)
|
||||||
.format(len(self.voice_states.get(ctx.message.guild.id).songs.entries)))
|
if state:
|
||||||
|
await ctx.send("There are a total of {} songs in the queue".format(len(state.songs.entries)))
|
||||||
|
else:
|
||||||
|
await ctx.send("There are no songs in the queue")
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
|
Loading…
Reference in a new issue