-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renaming the model variable to be more meaningful and refactoring the…
… cog to work be in extensions format
- Loading branch information
Showing
9 changed files
with
55 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from bot.core import DiscordBot | ||
|
||
from .commands import Levelling | ||
from .events import LevelEvents | ||
|
||
|
||
async def setup(bot: DiscordBot) -> None: | ||
await bot.add_cog(Levelling(bot=bot)) | ||
await bot.add_cog(LevelEvents(bot=bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import discord | ||
from discord.ext import commands | ||
|
||
from bot import core | ||
from bot.models import LevellingRole, PersistentRole | ||
|
||
|
||
class LevelEvents(commands.Cog): | ||
"""Events for Levelling in discord.""" | ||
|
||
def __init__(self, bot: core.DiscordBot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_level_up(self, new_level, member: discord.Member): | ||
"""Add roles when user levels up""" | ||
data = await LevellingRole.list_by_guild(guild_id=member.guild.id) | ||
for i in range(len(data)): | ||
# Adding roles when user levels up | ||
if new_level >= data[i].level and member.guild.get_role(data[i].role_id) not in member.roles: | ||
await member.add_roles(member.guild.get_role(data[i].role_id)) | ||
await PersistentRole.insert_by_guild( | ||
guild_id=member.guild.id, user_id=member.id, role_id=data[i].role_id | ||
) | ||
# Removing roles when users level down using remove_xp command | ||
elif new_level <= data[i].level and member.guild.get_role(data[i].role_id) in member.roles: | ||
await member.remove_roles(member.guild.get_role(data[i].role_id)) | ||
await PersistentRole.delete_by_guild(guild_id=member.guild.id, user_id=member.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters