Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ev.log.info(f'User {author.name} [{author.id}] sent a private message.')
embed = discord.Embed(color=0x0099FF)
if args and not ''.join(args) == '':
embed.add_field(name='Message',
value='```\n' + ' '.join(args) + '\n```', inline=False)
embed.set_footer(text=f'UserID: {author.id}')
embed.set_author(name=f'{author.name}#{author.discriminator}', icon_url=user_avatar(author))
if message.attachments:
attachment_links = ''
for attachment in message.attachments:
if attachment['url'].split('.')[-1] in ['png', 'jpg', 'jpeg', 'gif']:
embed.set_image(url=attachment['url'])
else:
attachment_links += '\n' + attachment['url']
embed.add_field(name='Attachments', value=attachment_links, inline=False)
owner = discord.utils.find(lambda usr: usr.id == permitted_id[0], ev.bot.get_all_members())
await ev.bot.send_message(owner, None, embed=embed)
if not ctx.server:
ctx.cmd_err = (1, "This is not valid outside of a server!")
return None
userstr = str(userstr)
if userstr.lower() in ["none", "0"]:
return None
if userstr == ".":
return ctx.ch.id
chid = userstr.strip('<#@!>')
if chid.isdigit():
def is_ch(ch):
return ch.id == chid
else:
def is_ch(ch):
return userstr.lower() in ch.name.lower()
ch = discord.utils.find(is_ch, ctx.server.channels)
if ch:
return ch.id
else:
ctx.cmd_err = (1, "I can't find the channel `{}` in this server!".format(userstr))
return None
It searches case-insensitively.
'''
match = USERNAME_DISCRIM_REGEX.match(name)
if match is None:
return None
name, discrim = match[1], int(match[2])
def check(user):
uname = normalize_caseless(user.name)
udiscrim = user.discriminator
return name == uname and discrim == udiscrim
name = normalize_caseless(name)
return discord.utils.find(check, users)
async def convert(self, ctx, argument):
id_ = self._get_id_match(argument)
if id_:
result = ctx.bot.get_guild(int(id_.group(1)))
else:
result = discord.utils.find(lambda g: g.name == argument, ctx.bot.guilds)
if not result:
raise commands.BadArgument(f'Could not find a guild matching <{argument}>', argument)
return result
"""Return a member object."""
"""
Parameters
----------
argument: str
text to parse
Returns
----------
discord.Member
member object to return
"""
ret = extract_id(argument)
t_st = argument.lower()
if not ret:
ret = discord.utils.find(lambda m: (m.id == ret) or
(t_st in [m.name.lower(), m.display_name.lower()]), # noqa
ctx.guild.members)
else:
ret = ctx.guild.get_member(int(ret))
if not ret:
ret = ctx.guild.get_member_named(t_st)
if ret:
return ret
else:
return None
def role_or_permissions(ctx, check, **perms):
if check_permissions(ctx, perms):
return True
ch = ctx.message.channel
author = ctx.message.author
if ch.is_private:
return False # can't have roles in PMs
role = discord.utils.find(check, author.roles)
return role is not None
"""
:param cmd: The command object referenced in the command.
:type cmd: sigma.core.mechanics.command.SigmaCommand
:param pld: The payload with execution data and details.
:type pld: sigma.core.mechanics.payload.CommandPayload
"""
if pld.msg.author.guild_permissions.manage_guild:
if len(pld.args) >= 2:
group_id = pld.args[0].lower()
lookup = ' '.join(pld.args[1:])
emote_groups = pld.settings.get('emote_role_groups', {})
if group_id in emote_groups:
bound_roles = emote_groups.get(group_id)
if len(bound_roles) < 10:
guild_roles = pld.msg.guild.roles
guild_role = discord.utils.find(lambda x: x.name.lower() == lookup.lower(), guild_roles)
if guild_role:
role_name = guild_role.name
if guild_role.id not in bound_roles:
bound_roles.append(guild_role.id)
emote_groups.update({group_id: bound_roles})
await cmd.db.set_guild_settings(pld.msg.guild.id, 'emote_role_groups', emote_groups)
response = ok(f'Added {role_name} to group {group_id}.')
else:
response = error(f'{role_name} is bound to {group_id}.')
else:
response = not_found(f'{lookup} not found.')
else:
response = error('Groups are limited to 10 roles.')
else:
response = not_found(f'Group {group_id} not found.')
else:
async def limbo(message, client):
'''
**{0}limbo** [*mention*]
*This command was created for the Vocaloid server. Just for Rodea. ;)*
This is a shortcut to add the "Limbo" role to a user. If your server has no "Limbo" role, this will fail.
*Example: `{0}limbo @CacoBot`*
'''
if message.channel.permissions_for(message.author).ban_members:
try:
foreboden = discord.utils.find(lambda m: m.name == 'Limbo', message.server.roles)
if foreboden != None:
for ment in message.mentions:
await client.replace_roles(ment, foreboden)
await client.send_message(message.channel, '{}: {} has been Limbo\'d.'.format(message.author.display_name, ment.name))
else:
await client.send_message(message.channel, '{}: You must create a role named \'Limbo\' before you can use this command.'.format(message.author.display_name))
except discord.Forbidden:
await client.send_message(message.channel, '{}: I do not have the permission to perform this command yet.'.format(message.author.display_name))
else:
await client.send_message(message.channel, '{}: You do not have the permission to manage roles.'.format(message.author.display_name))
async def linkrole(self, ctx, role_name: str, level: int, remove_role=None):
"""Associate a role with a level.
Removes previous role if given."""
server = ctx.guild
role_obj = discord.utils.find(lambda r: r.name == role_name, server.roles)
remove_role_obj = discord.utils.find(lambda r: r.name == remove_role, server.roles)
if role_obj is None or (remove_role is not None and remove_role_obj is None):
if remove_role is None:
await ctx.send("**Please make sure the `{}` role exists!**".format(role_name))
else:
await ctx.send(
"**Please make sure the `{}` and/or `{}` roles exist!**".format(role_name, remove_role))
else:
server_roles = db.roles.find_one({'server_id': str(server.id)})
if not server_roles:
new_server = {
'server_id': str(server.id),
'roles': {
role_name: {
'level': str(level),
'remove_role': remove_role
def _update_group(self, data):
owner_id = utils._get_as_snowflake(data, 'owner_id')
self.icon = data.get('icon')
self.name = data.get('name')
try:
self.recipients = [self._state.store_user(u) for u in data['recipients']]
except KeyError:
pass
if owner_id == self.me.id:
self.owner = self.me
else:
self.owner = utils.find(lambda u: u.id == owner_id, self.recipients)