1
0
Fork 0
mirror of synced 2024-05-20 20:42:27 +12:00

Update for rewrite: Batch 5

This commit is contained in:
phxntxm 2017-03-07 17:56:24 -06:00
parent d82127fa38
commit 2b9d8a2dca
10 changed files with 108 additions and 108 deletions

View file

@ -176,7 +176,7 @@ class Core:
embed = discord.Embed(**opts)
# Add the normal values
embed.add_field(name='Total Servers', value=len(self.bot.servers))
embed.add_field(name='Total Servers', value=len(self.bot.guilds))
embed.add_field(name='Total Members', value=len(set(self.bot.get_all_members())))
# Count the variable values; hangman, tictactoe, etc.

View file

@ -20,7 +20,7 @@ class StatsUpdate:
self.bot.loop.create_task(self.session.close())
async def update(self):
server_count = len(self.bot.servers)
server_count = len(self.bot.guilds)
carbon_payload = {
'key': config.carbon_key,
@ -67,7 +67,7 @@ class StatsUpdate:
return
channel = guild.get_channel(channel_id)
await channel.send("Welcome to the '{0.server.name}' server {0.mention}!".format(member))
await channel.send("Welcome to the '{0.guild.name}' server {0.mention}!".format(member))
async def on_member_remove(self, member):
guild = member.guild

View file

@ -23,7 +23,7 @@ class Mod:
EXAMPLE: !nick Music Bot
RESULT: My nickname is now Music Bot"""
await ctx.message.server.me.edit(nick=name)
await ctx.message.guild.me.edit(nick=name)
await ctx.send("\N{OK HAND SIGN}")
@commands.command(no_pm=True)
@ -107,8 +107,8 @@ class Mod:
EXAMPLE: !alerts #alerts
RESULT: No more alerts spammed in #general!"""
r_filter = {'server_id': ctx.message.server.id}
entry = {'server_id': ctx.message.server.id,
r_filter = {'server_id': ctx.message.guild.id}
entry = {'server_id': ctx.message.guild.id,
'channel_id': channel.id}
if not await utils.add_content('server_alerts', entry, r_filter):
await utils.update_content('server_alerts', entry, r_filter)
@ -319,7 +319,7 @@ class Mod:
"That command does not exist! You can't have custom permissions on a non-existant command....")
return
r_filter = {'server_id': ctx.message.server.id}
r_filter = {'server_id': ctx.message.guild.id}
await utils.replace_content('custom_permissions', r.row.without(cmd.qualified_name), r_filter)
await ctx.send("I have just removed the custom permissions for {}!".format(cmd))
@ -357,15 +357,15 @@ class Mod:
EXAMPLE: !purge 50
RESULT: -50 messages in this channel"""
if not ctx.message.channel.permissions_for(ctx.message.server.me).manage_messages:
if not ctx.message.channel.permissions_for(ctx.message.guild.me).manage_messages:
await ctx.send("I do not have permission to delete messages...")
return
try:
await ctx.message.channel.purge(limit=limit)
except discord.HTTPException:
await self.bot.send_message(ctx.message.channel, "Detected messages that are too far "
"back for me to delete; I can only bulk delete messages"
" that are under 14 days old.")
await ctx.message.channel.send("Detected messages that are too far "
"back for me to delete; I can only bulk delete messages"
" that are under 14 days old.")
@commands.command(no_pm=True)
@utils.custom_perms(manage_messages=True)
@ -387,7 +387,7 @@ class Mod:
if limit > 100:
limit = 100
if limit < 0:
await self.bot.say("Limit cannot be less than 0!")
await ctx.send("Limit cannot be less than 0!")
return
# If no members are provided, assume we're trying to prune our own messages
@ -407,8 +407,8 @@ class Mod:
# If we're not setting the user to the bot, then we're deleting someone elses messages
# To do so, we need manage_messages permission, so check if we have that
if not ctx.message.channel.permissions_for(ctx.message.server.me).manage_messages:
await self.bot.say("I do not have permission to delete messages...")
if not ctx.message.channel.permissions_for(ctx.message.guild.me).manage_messages:
await ctx.send("I do not have permission to delete messages...")
return
# Since logs_from will give us any message, not just the user's we need
@ -453,7 +453,7 @@ class Mod:
if rule is None:
try:
pages = utils.Pages(self.bot, message=ctx.message, entries=rules, per_page=5)
pages.title = "Rules for {}".format(ctx.message.server.name)
pages.title = "Rules for {}".format(ctx.message.guild.name)
await pages.paginate()
except utils.CannotPaginate as e:
await ctx.send(str(e))
@ -472,8 +472,8 @@ class Mod:
EXAMPLE: !rules add No fun allowed in this server >:c
RESULT: No more fun...unless they break the rules!"""
r_filter = {'server_id': ctx.message.server.id}
entry = {'server_id': ctx.message.server.id,
r_filter = {'server_id': ctx.message.guild.id}
entry = {'server_id': ctx.message.guild.id,
'rules': [rule]}
update = {'rules': r.row['rules'].append(rule)}
if not await utils.update_content('rules', update, r_filter):
@ -489,7 +489,7 @@ class Mod:
EXAMPLE: !rules delete 5
RESULT: Freedom from opression!"""
r_filter = {'server_id': ctx.message.server.id}
r_filter = {'server_id': ctx.message.guild.id}
update = {'rules': r.row['rules'].delete_at(rule - 1)}
if not await utils.update_content('rules', update, r_filter):
await ctx.send("That is not a valid rule number, try running the command again.")

View file

@ -148,9 +148,9 @@ class Music:
async def create_voice_client(self, channel):
"""Creates a voice client and saves it"""
# First join the channel and get the VoiceClient that we'll use to save per server
await self.remove_voice_client(channel.server)
await self.remove_voice_client(channel.guild)
server = channel.server
server = channel.guild
state = self.get_voice_state(server)
voice = self.bot.voice_client_in(server)
# Attempt 3 times
@ -198,7 +198,7 @@ class Music:
pass
async def on_voice_state_update(self, before, after):
state = self.get_voice_state(after.server)
state = self.get_voice_state(after.guild)
if state.voice is None:
return
voice_channel = state.voice.channel
@ -236,12 +236,12 @@ class Music:
# There's only one reaction we want to make sure we remove in the circumstances
# If the member doesn't have kick_members permissions, and isn't the requester
# Then they can't remove the song, otherwise they can
if not author.server_permissions.kick_members and author != entry.requester:
if not author.guild_permissions.kick_members and author != entry.requester:
try:
await self.bot.remove_reaction(message, '\u274c', channel.server.me)
await self.bot.remove_reaction(message, '\u274c', channel.guild.me)
except:
pass
elif not author.server_permissions.kick_members and author == entry.requester:
elif not author.guild_permissions.kick_members and author == entry.requester:
try:
await self.bot.add_reaction(message, '\u274c')
except:
@ -251,7 +251,7 @@ class Music:
await self.bot.add_reaction(message, '\N{LEFTWARDS BLACK ARROW}')
await self.bot.add_reaction(message, '\N{BLACK RIGHTWARDS ARROW}')
# The moderation tools that can be used
if author.server_permissions.kick_members:
if author.guild_permissions.kick_members:
await self.bot.add_reaction(message, '\N{DOWNWARDS BLACK ARROW}')
await self.bot.add_reaction(message, '\N{UPWARDS BLACK ARROW}')
await self.bot.add_reaction(message, '\N{CROSS MARK}')
@ -279,7 +279,7 @@ class Music:
# If up is clicked
elif '\u2b06' in reaction.emoji:
# A second check just to make sure, as well as ensuring index is higher than 0
if author.server_permissions.kick_members and index > 0:
if author.guild_permissions.kick_members and index > 0:
if entry != queue[index]:
fmt = "`Error: Position of this entry has changed, cannot complete your action`"
else:
@ -292,7 +292,7 @@ class Music:
# If down is clicked
elif '\u2b07' in reaction.emoji:
# A second check just to make sure, as well as ensuring index is lower than last
if author.server_permissions.kick_members and index < (count - 1):
if author.guild_permissions.kick_members and index < (count - 1):
if entry != queue[index]:
fmt = "`Error: Position of this entry has changed, cannot complete your action`"
else:
@ -305,7 +305,7 @@ class Music:
# If x is clicked
elif '\u274c' in reaction.emoji:
# A second check just to make sure
if author.server_permissions.kick_members or author == entry.requester:
if author.guild_permissions.kick_members or author == entry.requester:
if entry != queue[index]:
fmt = "`Error: Position of this entry has changed, cannot complete your action`"
else:
@ -333,7 +333,7 @@ class Music:
'bot': self.bot,
'ctx': ctx,
'message': ctx.message,
'server': ctx.message.server,
'server': ctx.message.guild,
'channel': ctx.message.channel,
'author': ctx.message.author
}
@ -345,10 +345,10 @@ class Music:
if inspect.isawaitable(result):
result = await result
except Exception as e:
await self.bot.say(python.format(type(e).__name__ + ': ' + str(e)))
await ctx.send(python.format(type(e).__name__ + ': ' + str(e)))
return
await self.bot.say(python.format(result))
await ctx.send(python.format(result))
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(send_messages=True)
@ -356,23 +356,23 @@ class Music:
"""Provides the progress of the current song"""
# Make sure we're playing first
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if not state.is_playing():
await self.bot.say('Not playing anything.')
await ctx.send('Not playing anything.')
else:
progress = state.current.progress
length = state.current.length
# Another check, just to make sure; this may happen for a very brief amount of time
# Between when the song was requested, and still downloading to play
if not progress or not length:
await self.bot.say('Not playing anything.')
await ctx.send('Not playing anything.')
return
# Otherwise just format this nicely
progress = divmod(round(progress, 0), 60)
length = divmod(round(length, 0), 60)
fmt = "Current song progress: {0[0]}m {0[1]}s/{1[0]}m {1[1]}s".format(progress, length)
await self.bot.say(fmt)
await ctx.send(fmt)
@commands.command(no_pm=True)
@utils.custom_perms(send_messages=True)
@ -382,14 +382,14 @@ class Music:
await self.create_voice_client(channel)
# Check if the channel given was an actual voice channel
except discord.InvalidArgument:
await self.bot.say('This is not a voice channel...')
await ctx.send('This is not a voice channel...')
except (asyncio.TimeoutError, discord.ConnectionClosed):
await self.bot.say("I failed to connect! This usually happens if I don't have permission to join the"
await ctx.send("I failed to connect! This usually happens if I don't have permission to join the"
" channel, but can sometimes be caused by your server region being far away."
" Otherwise this is an issue on Discord's end, causing the connect to timeout!")
await self.remove_voice_client(channel.server)
await self.remove_voice_client(channel.guild)
else:
await self.bot.say('Ready to play audio in ' + channel.name)
await ctx.send('Ready to play audio in ' + channel.name)
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(send_messages=True)
@ -399,22 +399,22 @@ class Music:
# First check if the author is even in a voice_channel
summoned_channel = ctx.message.author.voice_channel
if summoned_channel is None:
await self.bot.say('You are not in a voice channel.')
await ctx.send('You are not in a voice channel.')
return False
# Then simply create a voice client
try:
success = await self.create_voice_client(summoned_channel)
except (asyncio.TimeoutError, discord.ConnectionClosed):
await self.bot.say("I failed to connect! This usually happens if I don't have permission to join the"
await ctx.send("I failed to connect! This usually happens if I don't have permission to join the"
" channel, but can sometimes be caused by your server region being far away."
" Otherwise this is an issue on Discord's end, causing the connect to timeout!")
await self.remove_voice_client(summoned_channel.server)
await self.remove_voice_client(summoned_channel.guild)
return False
if success:
try:
await self.bot.say('Ready to play audio in ' + summoned_channel.name)
await ctx.send('Ready to play audio in ' + summoned_channel.name)
except discord.Forbidden:
pass
return success
@ -429,7 +429,7 @@ class Music:
The list of supported sites can be found here:
https://rg3.github.io/youtube-dl/supportedsites.html
"""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
# First check if we are connected to a voice channel at all, if not summon to the channel the author is in
# Since summon utils if the author is in a channel, we don't need to handle that here, just return if it failed
@ -440,21 +440,21 @@ class Music:
# If the queue is full, we ain't adding anything to it
if state.songs.full:
await self.bot.say("The queue is currently full! You'll need to wait to add a new song")
await ctx.send("The queue is currently full! You'll need to wait to add a new song")
return
author_channel = ctx.message.author.voice.voice_channel
my_channel = ctx.message.server.me.voice.voice_channel
my_channel = ctx.message.guild.me.voice.voice_channel
if my_channel is None:
# If we're here this means that after 3 attempts...4 different "failsafes"...
# Discord has returned saying the connection was successful, and returned a None connection
await self.bot.say("I failed to connect to the channel! Please try again soon")
await ctx.send("I failed to connect to the channel! Please try again soon")
return
# To try to avoid some abuse, ensure the requester is actually in our channel
if my_channel != author_channel:
await self.bot.say("You are not currently in the channel; please join before trying to request a song.")
await ctx.send("You are not currently in the channel; please join before trying to request a song.")
return
# Set the number of required skips to start
@ -502,32 +502,32 @@ class Music:
error = "{}...".format(error[:1996])
await self.bot.send_message(ctx.message.channel, error)
return
await self.bot.say('Enqueued ' + str(_entry))
await ctx.send('Enqueued ' + str(_entry))
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(kick_members=True)
async def volume(self, ctx, value: int = None):
"""Sets the volume of the currently playing song."""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if value is None:
volume = state.volume
await self.bot.say("Current volume is {}".format(volume))
await ctx.send("Current volume is {}".format(volume))
return
if value > 200:
await self.bot.say("Sorry but the max volume is 200")
await ctx.send("Sorry but the max volume is 200")
return
state.volume = value
if state.is_playing():
player = state.player
player.volume = value / 100
await self.bot.say('Set the volume to {:.0%}'.format(player.volume))
await ctx.send('Set the volume to {:.0%}'.format(player.volume))
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(kick_members=True)
async def pause(self, ctx):
"""Pauses the currently played song."""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if state.is_playing():
state.player.pause()
@ -535,7 +535,7 @@ class Music:
@utils.custom_perms(kick_members=True)
async def resume(self, ctx):
"""Resumes the currently played song."""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if state.is_playing():
state.player.resume()
@ -545,7 +545,7 @@ class Music:
"""Stops playing audio and leaves the voice channel.
This also clears the queue.
"""
server = ctx.message.server
server = ctx.message.guild
state = self.get_voice_state(server)
# Stop playing whatever song is playing.
@ -559,7 +559,7 @@ class Music:
try:
state.audio_player.cancel()
state.clear_audio_files()
await self.remove_voice_client(ctx.message.server)
await self.remove_voice_client(ctx.message.guild)
del self.voice_states[server.id]
except:
pass
@ -570,16 +570,16 @@ class Music:
"""Provides an ETA on when your next song will play"""
# Note: There is no way to tell how long a song has been playing, or how long there is left on a song
# That is why this is called an "ETA"
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
author = ctx.message.author
if not state.is_playing():
await self.bot.say('Not playing any music right now...')
await ctx.send('Not playing any music right now...')
return
queue = state.songs.entries
if len(queue) == 0:
await self.bot.say("Nothing currently in the queue")
await ctx.send("Nothing currently in the queue")
return
# Start off by adding the remaining length of the current song
@ -597,26 +597,26 @@ class Music:
# If it has not, then we have not looped through the queue at all
# Since the queue was already checked to have more than one song in it, this means the author is next
if count == state.current.duration:
await self.bot.say("You are next in the queue!")
await ctx.send("You are next in the queue!")
return
if not found:
await self.bot.say("You are not in the queue!")
await ctx.send("You are not in the queue!")
return
await self.bot.say("ETA till your next play is: {0[0]}m {0[1]}s".format(divmod(round(count, 0), 60)))
await ctx.send("ETA till your next play is: {0[0]}m {0[1]}s".format(divmod(round(count, 0), 60)))
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(send_messages=True)
async def queue(self, ctx):
"""Provides a printout of the songs that are in the queue"""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if not state.is_playing():
await self.bot.say('Not playing any music right now...')
await ctx.send('Not playing any music right now...')
return
# Asyncio provides no non-private way to access the queue, so we have to use _queue
queue = state.songs.entries
if len(queue) == 0:
await self.bot.say("Nothing currently in the queue")
await ctx.send("Nothing currently in the queue")
else:
self.bot.loop.create_task(self.queue_embed_task(state, ctx.message.channel, ctx.message.author))
@ -624,8 +624,8 @@ class Music:
@utils.custom_perms(send_messages=True)
async def queuelength(self, ctx):
"""Prints the length of the queue"""
await self.bot.say("There are a total of {} songs in the queue"
.format(len(self.get_voice_state(ctx.message.server).songs.entries)))
await ctx.send("There are a total of {} songs in the queue"
.format(len(self.get_voice_state(ctx.message.guild).songs.entries)))
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(send_messages=True)
@ -635,15 +635,15 @@ class Music:
are required to vote to skip for the song to be skipped.
"""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if not state.is_playing():
await self.bot.say('Not playing any music right now...')
await ctx.send('Not playing any music right now...')
return
# Check if the person requesting a skip is the requester of the song, if so automatically skip
voter = ctx.message.author
if voter == state.current.requester:
await self.bot.say('Requester requested skipping song...')
await ctx.send('Requester requested skipping song...')
state.skip()
# Otherwise check if the voter has already voted
elif voter.id not in state.skip_votes:
@ -652,33 +652,33 @@ class Music:
# Now check how many votes have been made, if 3 then go ahead and skip, otherwise add to the list of votes
if total_votes >= state.required_skips:
await self.bot.say('Skip vote passed, skipping song...')
await ctx.send('Skip vote passed, skipping song...')
state.skip()
else:
await self.bot.say('Skip vote added, currently at [{}/{}]'.format(total_votes, state.required_skips))
await ctx.send('Skip vote added, currently at [{}/{}]'.format(total_votes, state.required_skips))
else:
await self.bot.say('You have already voted to skip this song.')
await ctx.send('You have already voted to skip this song.')
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(kick_members=True)
async def modskip(self, ctx):
"""Forces a song skip, can only be used by a moderator"""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if not state.is_playing():
await self.bot.say('Not playing any music right now...')
await ctx.send('Not playing any music right now...')
return
state.skip()
await self.bot.say('Song has just been skipped.')
await ctx.send('Song has just been skipped.')
@commands.command(pass_context=True, no_pm=True)
@utils.custom_perms(send_messages=True)
async def playing(self, ctx):
"""Shows info about the currently played song."""
state = self.get_voice_state(ctx.message.server)
state = self.get_voice_state(ctx.message.guild)
if not state.is_playing():
await self.bot.say('Not playing anything.')
await ctx.send('Not playing anything.')
else:
# Create the embed object we'll use
embed = discord.Embed()
@ -696,7 +696,7 @@ class Music:
fmt = "{0[0]}m {0[1]}s/{1[0]}m {1[1]}s".format(progress, length)
embed.add_field(name='Progress', value=fmt,inline=False)
# And send the embed
await self.bot.say(embed=embed)
await ctx.send(embed=embed)
def setup(bot):

View file

@ -41,7 +41,7 @@ class Owner:
'bot': self.bot,
'ctx': ctx,
'message': ctx.message,
'server': ctx.message.server,
'server': ctx.message.guild,
'channel': ctx.message.channel,
'author': ctx.message.author
}

View file

@ -22,7 +22,7 @@ class Roles:
EXAMPLE: !role
RESULT: A list of all your roles"""
# Simply get a list of all roles in this server and send them
server_roles = [role.name for role in ctx.message.server.roles if not role.is_everyone]
server_roles = [role.name for role in ctx.message.guild.roles if not role.is_everyone]
await ctx.send("Your server's roles are: ```\n{}```".format("\n".join(server_roles)))
@role.command(name='remove', no_pm=True)
@ -33,12 +33,12 @@ class Roles:
EXAMPLE: !role remove @Jim @Bot @Joe
RESULT: A follow-along to remove the role(s) you want to, from these 3 members"""
# No use in running through everything if the bot cannot manage roles
if not ctx.message.server.me.permissions_in(ctx.message.channel).manage_roles:
if not ctx.message.guild.me.permissions_in(ctx.message.channel).manage_roles:
await ctx.send("I can't manage roles in this server, do you not trust me? :c")
return
check = lambda m: m.author == ctx.message.author and m.channel == ctx.message.channel
server_roles = [role for role in ctx.message.server.roles if not role.is_everyone]
server_roles = [role for role in ctx.message.guild.roles if not role.is_everyone]
# First get the list of all mentioned users
members = ctx.message.mentions
# If no users are mentioned, ask the author for a list of the members they want to remove the role from
@ -96,13 +96,13 @@ class Roles:
EXAMPLE: !role add @Bob @Joe @jim
RESULT: A follow along to add the roles you want to these 3"""
# No use in running through everything if the bot cannot manage roles
if not ctx.message.server.me.permissions_in(ctx.message.channel).manage_roles:
if not ctx.message.guild.me.permissions_in(ctx.message.channel).manage_roles:
await ctx.send("I can't manage roles in this server, do you not trust me? :c")
return
check = lambda m: m.author == ctx.message.author and m.channel == ctx.message.channel
# This is exactly the same as removing roles, except we call add_roles instead.
server_roles = [role for role in ctx.message.server.roles if not role.is_everyone]
server_roles = [role for role in ctx.message.guild.roles if not role.is_everyone]
members = ctx.message.mentions
if len(members) == 0:
await ctx.send("Please provide the list of members you want to add a role to")
@ -149,13 +149,13 @@ class Roles:
EXAMPLE: !role delete StupidRole
RESULT: No more role called StupidRole"""
# No use in running through everything if the bot cannot manage roles
if not ctx.message.server.me.permissions_in(ctx.message.channel).manage_roles:
if not ctx.message.guild.me.permissions_in(ctx.message.channel).manage_roles:
await ctx.send("I can't delete roles in this server, do you not trust me? :c")
return
# If no role was given, get the current roles on the server and ask which ones they'd like to remove
if role is None:
server_roles = [role for role in ctx.message.server.roles if not role.is_everyone]
server_roles = [role for role in ctx.message.guild.roles if not role.is_everyone]
await ctx.send(
"Which role would you like to remove from the server? Here is a list of this server's roles:"
@ -192,13 +192,13 @@ class Roles:
EXAMPLE: !role create
RESULT: A follow along in order to create a new role"""
# No use in running through everything if the bot cannot create the role
if not ctx.message.server.me.permissions_in(ctx.message.channel).manage_roles:
if not ctx.message.guild.me.permissions_in(ctx.message.channel).manage_roles:
await ctx.send("I can't create roles in this server, do you not trust me? :c")
return
# Save a couple variables that will be used repeatedly
author = ctx.message.author
server = ctx.message.server
server = ctx.message.guild
channel = ctx.message.channel
# A couple checks that will be used in the wait_for_message's

View file

@ -40,26 +40,26 @@ class Strawpoll:
RESULT: A list of all polls setup on this server"""
# Strawpolls cannot be 'deleted' so to handle whether a poll is running or not on a server
# Just save the poll, which can then be removed when it should not be "running" anymore
r_filter = {'server_id': ctx.message.server.id}
r_filter = {'server_id': ctx.message.guild.id}
polls = await config.get_content('strawpolls', r_filter)
# Check if there are any polls setup on this server
try:
polls = polls[0]['polls']
except TypeError:
await self.bot.say("There are currently no strawpolls running on this server!")
await ctx.send("There are currently no strawpolls running on this server!")
return
# Print all polls on this server if poll_id was not provided
if poll_id is None:
fmt = "\n".join(
"{}: https://strawpoll.me/{}".format(data['title'], data['poll_id']) for data in polls)
await self.bot.say("```\n{}```".format(fmt))
await ctx.send("```\n{}```".format(fmt))
else:
# Since strawpoll should never allow us to have more than one poll with the same ID
# It's safe to assume there's only one result
try:
poll = [p for p in polls if p['poll_id'] == poll_id][0]
except IndexError:
await self.bot.say("That poll does not exist on this server!")
await ctx.send("That poll does not exist on this server!")
return
async with self.session.get("{}/{}".format(self.url, poll_id),
@ -72,13 +72,13 @@ class Strawpoll:
# The rest is simple formatting
fmt_options = "\n\t".join(
"{}: {}".format(result, data['votes'][i]) for i, result in enumerate(data['options']))
author = discord.utils.get(ctx.message.server.members, id=poll['author'])
author = discord.utils.get(ctx.message.guild.members, id=poll['author'])
created_ago = (pendulum.utcnow() - pendulum.parse(poll['date'])).in_words()
link = "https://strawpoll.me/{}".format(poll_id)
fmt = "Link: {}\nTitle: {}\nAuthor: {}\nCreated: {} ago\nOptions:\n\t{}".format(link, data['title'],
author.display_name,
created_ago, fmt_options)
await self.bot.say("```\n{}```".format(fmt))
await ctx.send("```\n{}```".format(fmt))
@strawpolls.command(name='create', aliases=['setup', 'add'], pass_context=True, no_pm=True)
@checks.custom_perms(kick_members=True)
@ -103,7 +103,7 @@ class Strawpoll:
options = [option for option in options if option]
# If neither is found, then error out and let them know to use the help command, since this one is a bit finicky
else:
await self.bot.say(
await ctx.send(
"Please provide options for a new strawpoll! Use {}help {} if you do not know the format".format(
ctx.prefix, ctx.command.qualified_name))
return
@ -115,24 +115,24 @@ class Strawpoll:
async with self.session.post(self.url, data=json.dumps(payload), headers=self.headers) as response:
data = await response.json()
except json.JSONDecodeError:
await self.bot.say("Sorry, I couldn't connect to strawpoll at the moment. Please try again later")
await ctx.send("Sorry, I couldn't connect to strawpoll at the moment. Please try again later")
return
# Save this strawpoll in the list of running strawpolls for a server
poll_id = str(data['id'])
r_filter = {'server_id': ctx.message.server.id}
r_filter = {'server_id': ctx.message.guild.id}
sub_entry = {'poll_id': poll_id,
'author': ctx.message.author.id,
'date': str(pendulum.utcnow()),
'title': title}
entry = {'server_id': ctx.message.server.id,
entry = {'server_id': ctx.message.guild.id,
'polls': [sub_entry]}
update = {'polls': r.row['polls'].append(sub_entry)}
if not await config.update_content('strawpolls', update, r_filter):
await config.add_content('strawpolls', entry, {'poll_id': poll_id})
await self.bot.say("Link for your new strawpoll: https://strawpoll.me/{}".format(poll_id))
await ctx.send("Link for your new strawpoll: https://strawpoll.me/{}".format(poll_id))
@strawpolls.command(name='delete', aliases=['remove', 'stop'], pass_context=True, no_pm=True)
@checks.custom_perms(kick_members=True)
@ -141,12 +141,12 @@ class Strawpoll:
EXAMPLE: !strawpoll remove 5
RESULT: No more strawpoll 5~"""
r_filter = {'server_id': ctx.message.server.id}
r_filter = {'server_id': ctx.message.guild.id}
content = await config.get_content('strawpolls', r_filter)
try:
content = content[0]['polls']
except TypeError:
await self.bot.say("There are no strawpolls setup on this server!")
await ctx.send("There are no strawpolls setup on this server!")
return
polls = [poll for poll in content if poll['poll_id'] != poll_id]
@ -154,6 +154,6 @@ class Strawpoll:
update = {'polls': polls}
# Try to remove the poll based on the ID, if it doesn't exist, this will return false
if await config.update_content('strawpolls', update, r_filter):
await self.bot.say("I have just removed the poll with the ID {}".format(poll_id))
await ctx.send("I have just removed the poll with the ID {}".format(poll_id))
else:
await self.bot.say("There is no poll setup with that ID!")
await ctx.send("There is no poll setup with that ID!")

View file

@ -75,7 +75,7 @@ def custom_perms(**perms):
# The required permissions, based on the value saved
if perm_values:
for x in perm_values:
if x['server_id'] == ctx.message.server.id and x.get(ctx.command.qualified_name):
if x['server_id'] == ctx.message.guild.id and x.get(ctx.command.qualified_name):
required_perm = discord.Permissions(x[ctx.command.qualified_name])
# Now just check if the person running the command has these permissions

View file

@ -120,7 +120,7 @@ def command_prefix(bot, message):
# But it is not worth a query for every single message the bot detects, to fix
try:
values = cache['prefixes'].values
prefix = [data['prefix'] for data in values if message.server.id == data['server_id']][0]
prefix = [data['prefix'] for data in values if message.guild.id == data['server_id']][0]
return prefix or default_prefix
except (KeyError, TypeError, IndexError, AttributeError):
return default_prefix

View file

@ -145,7 +145,7 @@ class URLPlaylistEntry(BasePlaylistEntry):
meta['channel'] = ch or data['meta']['channel']['name']
if 'author' in data['meta']:
meta['author'] = meta['channel'].server.get_member(data['meta']['author']['id'])
meta['author'] = meta['channel'].guild.get_member(data['meta']['author']['id'])
return cls(playlist, url, title, duration, filename, **meta)