async def mute(self, ctx, *, user: str): """Chat mutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user and user != self.bot.user: failed = [] channel_length = 0 for channel in ctx.message.guild.channels: if type(channel) != discord.channel.TextChannel: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = False channel_length += 1 try: await channel.set_permissions(user, overwrite=overwrites) except discord.Forbidden: failed.append(channel) if failed and len(failed) < channel_length: await ctx.message.edit(content=self.bot.bot_prefix + "Muted user in {}/{} channels: {}".format(channel_length - len(failed), channel_length, user.mention)) elif failed: await ctx.message.edit(content=self.bot.bot_prefix + "Failed to mute user. Not enough permissions.") else: await ctx.message.edit(content=self.bot.bot_prefix + 'Muted user: %s' % user.mention) else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def unmute(self, ctx, *, user: str): """Unmutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user: for channel in ctx.message.server.channels: if channel.type != discord.ChannelType.text: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = None is_empty = self.are_overwrites_empty(overwrites) try: if not is_empty: await self.bot.edit_channel_permissions( channel, user, overwrites) else: await self.bot.delete_channel_permissions( channel, user) await self.bot.edit_channel_permissions( channel, user, overwrites) except discord.Forbidden: return await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Unable to unmute user. Not enough permissions.') await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Unmuted user: %s' % user.mention) else: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not find user.')
async def mute(self, ctx, *, user: str): """Chat mutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user and user != self.bot.user: failed = [] channel_length = 0 for channel in ctx.message.guild.channels: if type(channel) != discord.channel.TextChannel: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = False channel_length += 1 try: await channel.set_permissions(user, overwrite=overwrites) except discord.Forbidden: failed.append(channel) if failed and len(failed) < channel_length: await ctx.message.edit( content=self.bot.bot_prefix + "Muted user in {}/{} channels: {}".format( channel_length - len(failed), channel_length, user.mention)) elif failed: await ctx.message.edit( content=self.bot.bot_prefix + "Failed to mute user. Not enough permissions.") else: await ctx.message.edit(content=self.bot.bot_prefix + 'Muted user: %s' % user.mention) else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def setavatar(self, ctx, *, msg): """ Set an avatar from a URL or user. Usage: [p]setavatar <url_to_image> or [p]setavatar <user> to copy that user's avi Image URL must be a .png, a .jpg, or a .gif (nitro only) """ user = get_user(ctx.message, msg) if user: url = user.avatar_url_as(static_format='png') else: url = msg if ".gif" in url and not self.bot.user.premium: await ctx.send( self.bot.bot_prefix + "Warning: attempting to copy an animated avatar without Nitro. Only the first frame will be set." ) response = requests.get(url, stream=True) img = io.BytesIO() for block in response.iter_content(1024): if not block: break img.write(block) if url: img.seek(0) imgbytes = img.read() img.close() with open('settings/avatars.json', 'r+') as fp: opt = json.load(fp) if opt['password']: if opt['password'] == "": await ctx.send( self.bot.bot_prefix + "You have not set your password yet in `settings/avatars.json` Please do so and try again" ) else: pw = opt['password'] try: await self.bot.user.edit(password=pw, avatar=imgbytes) await ctx.send( self.bot.bot_prefix + "Your avatar has been set to the specified image." ) except discord.errors.HTTPException: await ctx.send(self.bot.bot_prefix + "You are being rate limited!") else: await ctx.send( "You have not set your password yet in `settings/avatars.json` Please do so and try again" ) else: await ctx.send(self.bot.bot_prefix + 'Could not find image.')
async def channel(self, ctx, *, user: str): user = get_user(ctx.message, user) if user: overwrites = ctx.message.channel.overwrites_for(user) overwrites.send_messages = False try: ctx.message.channel.set_permissions(user, overwrite=overwrites) await ctx.message.edit(content=self.bot.bot_prefix + 'Muted user in this channel: %s' % user.mention) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Unable to mute user. Not enough permissions.') else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def channel(self, ctx, *, user: str): user = get_user(ctx.message, user) if user: overwrites = ctx.message.channel.overwrites_for(user) overwrites.send_messages = False try: ctx.message.channel.set_permissions(user, overwrite=overwrites) await ctx.message.edit(content=self.bot.bot_prefix + 'Muted user in this channel: %s' % user.mention) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Unable to mute user. Not enough permissions.') else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def ban(self, ctx, user, *, reason=""): """Bans a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await user.ban(reason=reason) return_msg = "Banned user `{}`".format(user.mention) if reason: return_msg += " for reason `{}`".format(reason) return_msg += "." await ctx.message.edit(content=self.bot.bot_prefix + return_msg) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not ban user. Not enough permissions.') else: return await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def ban(self, ctx, *, user: str): """Bans a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await user.ban() await ctx.message.edit(content=self.bot.bot_prefix + 'Banned user: %s' % user.mention) except discord.Forbidden: await ctx.message.edit( content=self.bot.bot_prefix + 'Could not ban user. Not enough permissions.') else: return await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def ban(self, ctx, user, *, reason=""): """Bans a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await user.ban(reason=reason) return_msg = "Banned user `{}`".format(user.mention) if reason: return_msg += " for reason `{}`".format(reason) return_msg += "." await ctx.message.edit(content=self.bot.bot_prefix + return_msg) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not ban user. Not enough permissions.') else: return await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def kick(self, ctx, *, user: str): """Kicks a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await self.bot.kick(user) await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Kicked user: %s' % user.mention) except discord.Forbidden: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not kick user. Not enough permissions.') else: return await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not find user.')
async def softban(self, ctx, *, user: str): """Softbans a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await self.bot.ban(user) await self.bot.unban(ctx.message.server, user) await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Softbanned user: %s' % user.mention) except discord.Forbidden: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not softban user. Not enough permissions.') else: return await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not find user.')
async def setavatar(self, ctx, *, msg): """ Set an avatar from a URL or user. Usage: [p]setavatar <url_to_image> or [p]setavatar <user> to copy that user's avi Image URL must be a .png, a .jpg, or a .gif (nitro only) """ user = get_user(ctx.message, msg) if user: url = user.avatar_url_as(static_format='png') else: url = msg if ".gif" in url and not self.bot.user.premium: await ctx.send(self.bot.bot_prefix + "Warning: attempting to copy an animated avatar without Nitro. Only the first frame will be set.") response = requests.get(url, stream=True) img = io.BytesIO() for block in response.iter_content(1024): if not block: break img.write(block) if url: img.seek(0) imgbytes = img.read() img.close() with open('settings/avatars.json', 'r+') as fp: opt = json.load(fp) if opt['password']: if opt['password'] == "": await ctx.send(self.bot.bot_prefix + "You have not set your password yet in `settings/avatars.json` Please do so and try again") else: pw = opt['password'] try: await self.bot.user.edit(password=pw, avatar=imgbytes) await ctx.send(self.bot.bot_prefix + "Your avatar has been set to the specified image.") except discord.errors.HTTPException: await ctx.send(self.bot.bot_prefix + "You are being rate limited!") else: await ctx.send("You have not set your password yet in `settings/avatars.json` Please do so and try again") else: await ctx.send(self.bot.bot_prefix + 'Could not find image.')
async def unmute(self, ctx, *, user: str): """Unmutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user: failed = [] for channel in ctx.message.guild.channels: if type(channel) != discord.channel.TextChannel: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = None is_empty = self.are_overwrites_empty(overwrites) try: if not is_empty: await channel.set_permissions(user, overwrite=overwrites) else: await channel.set_permissions(user, overwrite=None) await channel.set_permissions(user, overwrite=overwrites) except discord.Forbidden: failed.append(channel) if failed and len(failed) < len(ctx.message.guild.channels): await ctx.message.edit( content=self.bot.bot_prefix + "Unmuted user in {}/{} channels: {}".format( len(ctx.message.guild.channels) - len(failed), len(ctx.message.guild.channels), user.mention)) elif failed: await ctx.message.edit( content=self.bot.bot_prefix + "Failed to unmute user. Not enough permissions.") else: await ctx.message.edit(content=self.bot.bot_prefix + 'Unmuted user: %s' % user.mention) else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
async def mute(self, ctx, *, user: str): """Chat mutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user and user != self.bot.user: for channel in ctx.message.server.channels: if channel.type != discord.ChannelType.text: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = False try: await self.bot.edit_channel_permissions( channel, user, overwrites) except discord.Forbidden: return await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Unable to mute user in one or more channels.') await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Muted user: %s' % user.mention) else: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not find user.')
async def channel(self, ctx, *, user: str): user = get_user(ctx.message, user) if user: overwrites = ctx.message.channel.overwrites_for(user) is_empty = self.are_overwrites_empty(overwrites) try: if not is_empty: await self.bot.edit_channel_permissions( ctx.message.channel, user, overwrites) else: await self.bot.delete_channel_permissions( ctx.message.channel, user) await self.bot.edit_channel_permissions( ctx.message.channel, user, overwrites) await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Unmuted user in this channel: %s' % user.mention) except discord.Forbidden: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Unable to unmute user. Not enough permissions.') else: await self.bot.edit_message( ctx.message, self.bot.bot_prefix + 'Could not find user.')
async def quote(self, ctx, *, msg: str = ""): """Quote a message. [p]help quote for more info. [p]quote - quotes the last message sent in the channel. [p]quote <words> - tries to search for a message in the server that contains the given words and quotes it. [p]quote <message_id> - quotes the message with the given message ID. Ex: [p]quote 302355374524644290 (enable developer mode to copy message IDs) [p]quote <user_mention_name_or_id> - quotes the last message sent by a specific user [p]quote <words> | channel=<channel_name> - quotes the message with the given words in a specified channel [p]quote <message_id> | channel=<channel_name> - quotes the message with the given message ID in a specified channel [p]quote <user_mention_name_or_id> | channel=<channel_name> - quotes the last message sent by a specific user in a specified channel """ await ctx.message.delete() result = None channels = [ctx.channel] + [x for x in ctx.guild.channels if x != ctx.channel and type(x) == discord.channel.TextChannel] args = msg.split(" | ") msg = args[0] if len(args) > 1: channel = args[1].split("channel=")[1] channels = [] for chan in ctx.guild.channels: if chan.name == channel or str(chan.id) == channel: channels.append(chan) break else: for guild in self.bot.guilds: for chan in guild.channels: if chan.name == channel or str(chan.id) == channel and type(chan) == discord.channel.TextChannel: channels.append(chan) break if not channels: return await ctx.send(self.bot.bot_prefix + "The specified channel could not be found.") user = get_user(ctx.message, msg) async def get_quote(msg, channels, user): for channel in channels: try: if user: async for message in channel.history(limit=500): if message.author == user: return message if len(msg) > 15 and msg.isdigit(): async for message in channel.history(limit=500): if str(message.id) == msg: return message else: async for message in channel.history(limit=500): if msg in message.content: return message except discord.Forbidden: continue return None if msg: result = await get_quote(msg, channels, user) else: async for message in ctx.channel.history(limit=1): result = message if result: if type(result.author) == discord.User: sender = result.author.name else: sender = result.author.nick if result.author.nick else result.author.name if embed_perms(ctx.message) and result.content: color = get_config_value("optional_config", "quoteembed_color") if color == "auto": color = result.author.top_role.color elif color == "": color = 0xbc0b0b else: color = int('0x' + color, 16) em = discord.Embed(color=color, description=result.content, timestamp=result.created_at) em.set_author(name=sender, icon_url=result.author.avatar_url) footer = "" if result.channel != ctx.channel: footer += "#" + result.channel.name if result.guild != ctx.guild: footer += " | " + result.guild.name if footer: em.set_footer(text=footer) await ctx.send(embed=em) elif result.content: await ctx.send('%s - %s```%s```' % (sender, result.created_at, result.content)) else: await ctx.send(self.bot.bot_prefix + "Embeds cannot be quoted.") else: await ctx.send(self.bot.bot_prefix + 'No quote found.')
async def quote(self, ctx, *, msg: str = None): """Quote a message. >help quote for more info. >quote - quotes the last message sent in the channel. >quote <words> - tries to search for a message in the server that contains the given words and quotes it. >quote <message_id> - quotes the message with the given message id. Ex: >quote 302355374524644290(Enable developer mode to copy message ids). >quote <words> | channel=<channel_name> - quotes the message with the given words from the channel name specified in the second argument >quote <message_id> | channel=<channel_name> - quotes the message with the given message id in the given channel name >quote <user_mention_name_or_id> - quotes the last member sent by a specific user""" await ctx.message.delete() result = None pre = cmd_prefix_len() channel = ctx.channel if msg: user = get_user(ctx.message, msg) if " | channel=" in msg: channel = next((ch for ch in self.bot.get_all_channels() if ch.name == msg.split("| channel=")[1]), None) msg = msg.split(" | channel=")[0] if not channel: return await ctx.send(self.bot.bot_prefix + "Could not find specified channel.") if not isinstance(channel, discord.channel.TextChannel): return await ctx.send( self.bot.bot_prefix + "This command is only supported in server text channels.") try: length = len(self.bot.all_log[str(ctx.message.channel.id) + ' ' + str(ctx.message.guild.id)]) except: pass else: size = length if length < 201 else 200 for channel in ctx.message.guild.channels: if type(channel) == discord.channel.TextChannel: if str(channel.id) + ' ' + str( ctx.message.guild.id) in self.bot.all_log: for i in range(length - 2, length - size, -1): try: search = self.bot.all_log[ str(channel.id) + ' ' + str(ctx.message.guild.id)][i] except: continue if (msg.lower().strip() in search[0].content.lower() and (search[0].author != ctx.message.author or search[0].content[pre:7] != 'quote ') ) or (ctx.message.content[6:].strip() == str(search[0].id)) or ( search[0].author == user and search[0].channel == ctx.message.channel): result = search[0] break if result: break if not result: try: async for sent_message in channel.history(limit=500): if (msg.lower().strip() in sent_message.content and (sent_message.author != ctx.message.author or sent_message.content[pre:7] != 'quote ')) or ( msg.strip() == str( sent_message.id)) or (msg.author == user): result = sent_message break except: pass else: if not isinstance(channel, discord.channel.TextChannel): return await ctx.send( self.bot.bot_prefix + "This command is only supported in server text channels.") try: search = self.bot.all_log[str(ctx.message.channel.id) + ' ' + str(ctx.message.guild.id)][-2] result = search[0] except KeyError: try: messages = await channel.history(limit=2).flatten() result = messages[0] except: pass if result: sender = result.author.nick if result.author.nick else result.author.name if embed_perms(ctx.message) and result.content: color = get_config_value("optional_config", "quoteembed_color") if color == "auto": color = result.author.top_role.color elif color == "": color = 0xbc0b0b else: color = int('0x' + color, 16) em = discord.Embed(color=color, description=result.content, timestamp=result.created_at) em.set_author(name=sender, icon_url=result.author.avatar_url) if channel != ctx.message.channel: em.set_footer(text='#{} | {} '.format( channel.name, channel.guild.name)) await ctx.send(embed=em) else: await ctx.send('%s - %s```%s```' % (sender, result.created_at, result.content)) else: await ctx.send(self.bot.bot_prefix + 'No quote found.')
async def quote(self, ctx, *, msg: str = ""): """Quote a message. [p]help quote for more info. [p]quote - quotes the last message sent in the channel. [p]quote <words> - tries to search for a message in the server that contains the given words and quotes it. [p]quote <message_id> - quotes the message with the given message ID. Ex: [p]quote 302355374524644290 (enable developer mode to copy message IDs) [p]quote <user_mention_name_or_id> - quotes the last message sent by a specific user [p]quote <words> | channel=<channel_name> - quotes the message with the given words in a specified channel [p]quote <message_id> | channel=<channel_name> - quotes the message with the given message ID in a specified channel [p]quote <user_mention_name_or_id> | channel=<channel_name> - quotes the last message sent by a specific user in a specified channel """ ###await ctx.message.delete() result = None channels = [ctx.channel] + [x for x in ctx.guild.channels if x != ctx.channel and type(x) == discord.channel.TextChannel] args = msg.split(" | ") msg = args[0] if len(args) > 1: channel = args[1].split("channel=")[1] channels = [] for chan in ctx.guild.channels: if chan.name == channel or str(chan.id) == channel: channels.append(chan) break else: for guild in self.bot.guilds: for chan in guild.channels: if chan.name == channel or str(chan.id) == channel and type(chan) == discord.channel.TextChannel: channels.append(chan) break if not channels: return await ctx.send(self.bot.bot_prefix + "The specified channel could not be found.") user = get_user(ctx.message, msg) async def get_quote(msg, channels, user): for channel in channels: try: if user: async for message in channel.history(limit=500): if message.author == user: return message if len(msg) > 15 and msg.isdigit(): async for message in channel.history(limit=500): if str(message.id) == msg: return message else: async for message in channel.history(limit=500): if msg in message.content: return message except discord.Forbidden: continue return None if msg: result = await get_quote(msg, channels, user) else: async for message in ctx.channel.history(limit=1): result = message if result: if type(result.author) == discord.User: sender = result.author.name else: sender = result.author.nick if result.author.nick else result.author.name if embed_perms(ctx.message) and result.content: color = get_config_value("optional_config", "quoteembed_color") if color == "auto": color = result.author.top_role.color elif color == "": color = 0xbc0b0b else: color = int('0x' + color, 16) em = discord.Embed(color=color, description=result.content, timestamp=result.created_at) em.set_author(name=sender, icon_url=result.author.avatar_url) footer = "" if result.channel != ctx.channel: footer += "#" + result.channel.name if result.guild != ctx.guild: footer += " | " + result.guild.name if footer: em.set_footer(text=footer) await ctx.send(embed=em) elif result.content: await ctx.send('%s - %s```%s```' % (sender, result.created_at, result.content)) else: await ctx.send(self.bot.bot_prefix + "Embeds cannot be quoted.") else: await ctx.send(self.bot.bot_prefix + 'No quote found.')