Merge pull request #4 from HF-Vitriol/patch-1

Code is now more Efficient. 
Using Lambda/Filters/FrozenSets
pull/5/head
Hamothy 4 years ago committed by GitHub
commit 7058341a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,42 +10,36 @@ from discord.ext.commands import BucketType, cooldown, command
import settings import settings
# Permissions to filter through # Permissions to filter through
Perms = {"create instant invite": "", Perms = frozenset(
"add reactions": "", {
"view audit log": "", "create instant invite",
"priority speaker": "", "add reactions",
"stream": "", "view audit log",
"read messages": "", "priority speaker",
"send messages": "", "stream",
"send tts messages": "", "read messages",
"embed links": "", "send messages",
"attach links": "", "send tts messages",
"read message history": "", "embed links",
"external emojis": "", "attach links",
"view guild insights": "", "read message history",
"connect": "", "external emojis",
"speak": "", "view guild insights",
"use voice activation": "", "connect": "",
"change nickname": ""} "speak": "",
"use voice activation",
"change nickname"
}
)
# Method to detect which permissions to filter out # Method to detect which permissions to filter out
def DetectPermissions(message, dct): def DetectPermissions(message, fset):
# Split the message individual permissions # Split the message individual permissions
message = message.split(",") message = message.split(",")
new_msg = ""
# For every permission
for word in message:
# Add the permission in the new string if the permission is not in the dictionary
if word not in dct:
new_msg += word + ", "
# Do nothing if the permission is in the dictionary
else:
pass
return new_msg
# Filter the permission out if it's in the frozenset
filtered = filter(lambda perm: perm not in fset, message)
return ",".join(filtered)
class GetInfo(commands.Cog): class GetInfo(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
@ -70,25 +64,14 @@ class GetInfo(commands.Cog):
mentions = [role.mention for role in target.roles] mentions = [role.mention for role in target.roles]
# Store the roles in a string called "roles" # Store the roles in a string called "roles"
roles = ""
# For each role that the user has (Skipping the first element as it's always going to be @everyone # For each role that the user has (Skipping the first element as it's always going to be @everyone
for role in mentions[1:]:
# Add the role to the string
roles += role + ' '
# Store all the permissions that the user has in a string # Store all the permissions that the user has in a string
permission = "" roles = " ".join(mentions[1:])
# For each permission that the user has
for perms in target.guild_permissions:
# If the permission is set to "True"
if perms[1]:
# Make the string look nice by replacing _ with a space
permission += (perms[0].replace('_', ' ')) + ','
# If the permission is set to "False", Don't do anything # filter out the ones with permission set to False
else: filtered = filter(lambda x: x[1], target.guild_permissions)
pass # now replace all "_" with " " in each item and join them together
permission = ",".join(map(lambda x: x[0].replace("_", " "), filtered))
# Capitalise every word in the array and get rid of the ", " at the end of the string # Capitalise every word in the array and get rid of the ", " at the end of the string
permissions = string.capwords("".join(map(str, DetectPermissions(permission, Perms)[0:-4]))) permissions = string.capwords("".join(map(str, DetectPermissions(permission, Perms)[0:-4])))
@ -97,7 +80,8 @@ class GetInfo(commands.Cog):
embed = Embed( embed = Embed(
title=f"**User Information**", title=f"**User Information**",
colour=Colour(int(random.choice(settings.colour_list))), colour=Colour(int(random.choice(settings.colour_list))),
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow()
)
embed.set_thumbnail(url=userAvatar) embed.set_thumbnail(url=userAvatar)
embed.set_footer(text=f"ID: {target.id}", icon_url='{}'.format(userAvatar)) embed.set_footer(text=f"ID: {target.id}", icon_url='{}'.format(userAvatar))

Loading…
Cancel
Save