Browse Source

finally got self assign to work with roles that have spaces

tags/v1.0.0
roxie 6 years ago
parent
commit
8c8362cf9c
3 changed files with 19 additions and 17 deletions
  1. +17
    -15
      cogs/selfassign.py
  2. +1
    -1
      config/server_config.py
  3. +1
    -1
      config/servers.json

+ 17
- 15
cogs/selfassign.py View File

Usage: Usage:
{command_prefix}listroles {command_prefix}listroles
""" """
if not self.servers[ctx.message.server.id]["selfAssign"]["enabled"]:
if not self.servers[ctx.message.server.id]["self_assign"]["enabled"]:
embed = discord.Embed(colour=discord.Colour(0xDEADBF), # Make Embed colour a constant embed = discord.Embed(colour=discord.Colour(0xDEADBF), # Make Embed colour a constant
description="SelfAssignable roles are not enabled on this server") description="SelfAssignable roles are not enabled on this server")
return await self.bot.say(embed=embed) return await self.bot.say(embed=embed)
roles = [] roles = []
for role in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
for role in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
for serverrole in ctx.message.server.roles: for serverrole in ctx.message.server.roles:
if role == serverrole.id: if role == serverrole.id:
roles.append("**"+serverrole.name+"**") roles.append("**"+serverrole.name+"**")
return await self.bot.say(embed=embed) return await self.bot.say(embed=embed)


@commands.command(pass_context=True) @commands.command(pass_context=True)
async def iam(self, ctx, role: discord.Role = None):
async def iam(self, ctx, *, role: discord.Role = None):
""" """
Self-assign yourself a role. Only one role at a time. Self-assign yourself a role. Only one role at a time.
Usage: Usage:
.iam OverwatchPing .iam OverwatchPing
""" """
self.servers = self.con.load_config() self.servers = self.con.load_config()
if not self.servers[ctx.message.server.id]["selfAssign"]["enabled"]:
if not self.servers[ctx.message.server.id]["self_assign"]["enabled"]:
return return


user = ctx.message.author user = ctx.message.author
if role in user.roles: if role in user.roles:
return await self.bot.say("You already have that role.") return await self.bot.say("You already have that role.")


if role.id in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
if role.id in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
await self.bot.add_roles(user, role) await self.bot.add_roles(user, role)
print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel, print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel,
ctx.message.server)) ctx.message.server))
return await self.bot.say("That role is not self-assignable.") return await self.bot.say("That role is not self-assignable.")


@commands.command(pass_context=True) @commands.command(pass_context=True)
async def iamn(self, ctx, role: discord.Role = None):
async def iamn(self, ctx, *, role: discord.Role = None):
""" """
Remove a self-assigned role Remove a self-assigned role
Usage: Usage:
.iamn OverwatchPing .iamn OverwatchPing
""" """
self.servers = self.con.load_config() self.servers = self.con.load_config()
if not self.servers[ctx.message.server.id]["selfAssign"]["enabled"]:
if not self.servers[ctx.message.server.id]["self_assign"]["enabled"]:
print("Self Assign is Disabled")
return return


user = ctx.message.author user = ctx.message.author
if role not in server.roles: if role not in server.roles:
return await self.bot.say("That role doesn't exist. Roles are case sensitive. ") return await self.bot.say("That role doesn't exist. Roles are case sensitive. ")


elif role in user.roles and role.id in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
elif role in user.roles and role.id in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
print("passed in server check")
await self.bot.remove_roles(user, role) await self.bot.remove_roles(user, role)
return await self.bot.reply("{} has been successfully removed.".format(role.name)) return await self.bot.reply("{} has been successfully removed.".format(role.name))


elif role not in user.roles and role.id in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
elif role not in user.roles and role.id in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
return await self.bot.reply("You do not have {}.".format(role.name)) return await self.bot.reply("You do not have {}.".format(role.name))
else: else:
return await self.bot.say("That role is not self-assignable.") return await self.bot.say("That role is not self-assignable.")


@commands.command(pass_context=True, hidden=True) @commands.command(pass_context=True, hidden=True)
@checks.is_bot_owner() @checks.is_bot_owner()
async def addrole(self, ctx, role: discord.Role = None):
async def addrole(self, ctx, *, role: discord.Role = None):
""" """
] Adds a role to the list of roles that can be self assigned for that server. ] Adds a role to the list of roles that can be self assigned for that server.
""" """
self.servers = self.con.load_config() self.servers = self.con.load_config()
if role.id in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
if role.id in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
return await self.bot.say("{} is already a self-assignable role.".format(role.name), delete_after=self.con.delete_after) return await self.bot.say("{} is already a self-assignable role.".format(role.name), delete_after=self.con.delete_after)


self.servers[ctx.message.server.id]["selfAssign"]["roles"].append(role.id)
self.servers[ctx.message.server.id]["self_assign"]["roles"].append(role.id)
self.con.update_config(self.servers) self.con.update_config(self.servers)
return await self.bot.say('Role "{}" added'.format(str(role))) return await self.bot.say('Role "{}" added'.format(str(role)))


@commands.command(pass_context=True, hidden=True) @commands.command(pass_context=True, hidden=True)
@checks.is_bot_owner() @checks.is_bot_owner()
async def removerole(self, ctx, role: discord.Role = None):
async def removerole(self, ctx, *, role: discord.Role = None):
""" """
Removes a role from the list of self assignable roles for that server. Removes a role from the list of self assignable roles for that server.
""" """
self.servers = self.con.load_config() self.servers = self.con.load_config()
if role.id in self.servers[ctx.message.server.id]["selfAssign"]["roles"]:
self.servers[ctx.message.server.id]["selfAssign"]["roles"].remove(role.id)
if role.id in self.servers[ctx.message.server.id]["self_assign"]["roles"]:
self.servers[ctx.message.server.id]["self_assign"]["roles"].remove(role.id)
self.con.update_config(self.servers) self.con.update_config(self.servers)
return await self.bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role))) return await self.bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role)))
else: else:

+ 1
- 1
config/server_config.py View File

"enabled": 0, "enabled": 0,
"goodbye-channel": "", "goodbye-channel": "",
}, },
"selfAssign": {
"self_assign": {
"enabled": 0, "enabled": 0,
"roles": [] "roles": []
}, },

+ 1
- 1
config/servers.json View File

{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": ["307330606348632064", "308081662787321861", "308081544273199106"]}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}}}
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 1, "roles": ["307330606348632064", "308081662787321861", "308081544273199106", "308081490296569889"]}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}}}

Loading…
Cancel
Save