Making code more efficient

Using map/.join/filter/lambda
pull/8/head
sgoudham 4 years ago
parent 6d8b63fb46
commit b375e6a209

@ -25,13 +25,14 @@ Perms = frozenset(
"read message history",
"external emojis",
"view guild insights",
"connect": "",
"speak": "",
"connect",
"speak",
"use voice activation",
"change nickname"
}
)
# Method to detect which permissions to filter out
def DetectPermissions(message, fset):
# Split the message individual permissions
@ -41,6 +42,7 @@ def DetectPermissions(message, fset):
filtered = filter(lambda perm: perm not in fset, message)
return ", ".join(filtered)
class GetInfo(commands.Cog):
def __init__(self, bot):
self.bot = bot
@ -64,7 +66,7 @@ class GetInfo(commands.Cog):
mentions = [role.mention for role in target.roles]
# Store the roles in a string called "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)
# Store all the permissions that the user has in a string
roles = " ".join(mentions[1:])
@ -74,7 +76,7 @@ class GetInfo(commands.Cog):
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
permissions = string.capwords("".join(map(str, DetectPermissions(permission, Perms)[0:-4])))
permissions = string.capwords("".join(map(str, DetectPermissions(permission, Perms))))
# Set up the embed to display everything about the user
embed = Embed(
@ -135,7 +137,7 @@ class GetInfo(commands.Cog):
("\u200b", "\u200b", False),
("Members", len(ctx.guild.members), True),
("Humans", len(list(filter(lambda m: not m.bot, ctx.guild.members))), True),
("Bots", len(list(filter(lambda c: c.bot, ctx.guild.members))), True),
("Bots", len(list(filter(lambda m: m.bot, ctx.guild.members))), True),
("Banned Members", len(await ctx.guild.bans()), True),
("Text Channels", len(ctx.guild.text_channels), True),
("Voice Channels", len(ctx.guild.voice_channels), True),

Loading…
Cancel
Save