|
9 | 9 | import discord |
10 | 10 | from discord.ext.commands import Bot |
11 | 11 | from sqlalchemy import select, text, delete, and_ |
| 12 | +from sqlalchemy.exc import IntegrityError |
12 | 13 | from sqlalchemy.orm import Session |
13 | 14 |
|
14 | 15 | import koalabot |
@@ -120,28 +121,39 @@ async def re_verify_role(guild_id, role_id, bot: koalabot.KoalaBot, *, session: |
120 | 121 |
|
121 | 122 |
|
122 | 123 | @assign_session |
123 | | -async def blacklist_member(user_id, guild_id, role_id, suffix, bot: Bot, **kwargs): |
| 124 | +async def blacklist_member(user_id, guild_id, role_id, suffix, bot: Bot, *, session: Session): |
124 | 125 | guild: discord.Guild = bot.get_guild(guild_id) |
125 | 126 | role = guild.get_role(role_id) |
126 | 127 |
|
127 | 128 | if not role: |
128 | 129 | raise InvalidArgumentError("Please mention a role in this guild") |
129 | 130 |
|
130 | | - db.add_to_blacklist(user_id, role.id, suffix, **kwargs) |
131 | | - await remove_roles_for_user(user_id, suffix, bot, **kwargs) |
| 131 | + blacklisted = VerifyBlacklist(user_id=user_id, role_id=role_id, email_suffix=suffix) |
| 132 | + try: |
| 133 | + session.add(blacklisted) |
| 134 | + session.commit() |
| 135 | + except IntegrityError: |
| 136 | + raise errors.VerifyException("This user verification is already blacklisted.") |
| 137 | + await remove_roles_for_user(user_id, suffix, bot, session=session) |
132 | 138 |
|
133 | 139 |
|
134 | 140 | @assign_session |
135 | | -async def remove_blacklist_member(user_id, guild_id, role_id, suffix, bot: Bot, **kwargs): |
| 141 | +async def remove_blacklist_member(user_id, guild_id, role_id, suffix, bot: Bot, *, session: Session): |
136 | 142 | guild: discord.Guild = bot.get_guild(guild_id) |
137 | 143 | role = guild.get_role(role_id) |
138 | 144 |
|
139 | 145 | if not role: |
140 | 146 | raise InvalidArgumentError("Please mention a role in this guild") |
141 | 147 |
|
142 | | - db.remove_from_blacklist(user_id, role.id, suffix, **kwargs) |
143 | | - await assign_roles_for_user(user_id, suffix, bot, **kwargs) |
144 | | - await assign_role_to_guild(guild, role, suffix) |
| 148 | + blacklisted = session.execute(select(VerifyBlacklist) |
| 149 | + .filter_by(user_id=user_id, role_id=role_id, email_suffix=suffix)).scalar() |
| 150 | + if not blacklisted: |
| 151 | + raise errors.VerifyException("This user verification blacklist doesn't exist.") |
| 152 | + session.delete(blacklisted) |
| 153 | + session.commit() |
| 154 | + |
| 155 | + await assign_roles_for_user(user_id, suffix, bot, session=session) |
| 156 | + await assign_role_to_guild(guild, role, suffix, session=session) |
145 | 157 |
|
146 | 158 |
|
147 | 159 | @assign_session |
|
0 commit comments