Skip to content

Commit db0656c

Browse files
committed
chore: review fixes
1 parent c9a0427 commit db0656c

File tree

3 files changed

+20
-47
lines changed

3 files changed

+20
-47
lines changed

koala/cogs/verification/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class VerifyEndpoint:
2424
"""
25-
The API endpoints for BaseCog
25+
The API endpoints for Verify
2626
"""
2727
def __init__(self, bot):
2828
self._bot = bot

koala/cogs/verification/core.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import discord
1010
from discord.ext.commands import Bot
1111
from sqlalchemy import select, text, delete, and_
12+
from sqlalchemy.exc import IntegrityError
1213
from sqlalchemy.orm import Session
1314

1415
import koalabot
@@ -120,28 +121,39 @@ async def re_verify_role(guild_id, role_id, bot: koalabot.KoalaBot, *, session:
120121

121122

122123
@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):
124125
guild: discord.Guild = bot.get_guild(guild_id)
125126
role = guild.get_role(role_id)
126127

127128
if not role:
128129
raise InvalidArgumentError("Please mention a role in this guild")
129130

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)
132138

133139

134140
@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):
136142
guild: discord.Guild = bot.get_guild(guild_id)
137143
role = guild.get_role(role_id)
138144

139145
if not role:
140146
raise InvalidArgumentError("Please mention a role in this guild")
141147

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)
145157

146158

147159
@assign_session

koala/cogs/verification/db.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)