Skip to content

Commit

Permalink
Release 4.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisHobden committed Jun 21, 2021
1 parent b47dbc0 commit 51d50d7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.10.1] - 2021-06-21
### Booster Features
- Booster roles are now automatically removed and deleted when a user no longer boosts the server.
- Fixed a bug with the importer.

## [4.10.0] - 2021-06-21
### Booster Features
- You can now configure messages to be posted when a person newly boosts a server.
Expand Down
21 changes: 21 additions & 0 deletions cogs/booster.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,31 @@ def _get_booster_role(roles, anchor_position):
return role


async def _on_member_updated(member_before: Member, member_after: Member):
if member_after.premium_since is not None:
return

booster_role = BoosterRole.get_for_member(member_after)

if booster_role is None:
return

assigned_role = discord.utils.get(member_after.roles, id=booster_role.role_id)

# The role may already be deleted.
if assigned_role is None:
return

await member_after.remove_roles(assigned_role)
await assigned_role.delete()


class BoosterRoleCog(commands.Cog, name="Booster Roles"):
def __init__(self, client: commands.Bot):
self.client = client

client.add_listener(_on_member_updated, "on_member_update")

@commands.command(name="boosterrole", aliases=["br", "myrole"])
async def _booster_role(self, ctx, instruction: str = None, field: str = None, *, value: str = None):
""" A command that allows you to edit your own booster role! You must Nitro boost this server for it to work.
Expand Down
9 changes: 9 additions & 0 deletions model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ class BoosterRole(BaseModel):
def add_for_member(cls, member: Member, role: Role):
return cls.create(guild_id=member.guild.id, user_id=member.id, role_id=role.id)

@classmethod
def delete_for_member(cls, member: Member):
record = cls.get_or_none((cls.guild_id == member.guild.id) & (cls.user_id == member.id))

if record is None:
return

record.delete_instance()

@classmethod
def get_for_member(cls, member: Member):
return cls.get_or_none((cls.guild_id == member.guild.id) & (cls.user_id == member.id))
Expand Down

0 comments on commit 51d50d7

Please sign in to comment.