Skip to content

Commit e756a94

Browse files
Rename some blacklist object fields
1 parent 7283346 commit e756a94

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

commands/blacklist.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ async def add(self, ctx: Context, item: str):
4646
author_id = db_session.query(User).filter(User.user_uid == ctx.message.author.id).first().id
4747

4848
if not db_session.query(BlockedKarma) \
49-
.filter(BlockedKarma.name == item.casefold()).all():
50-
blacklist = BlockedKarma(name=item.casefold(), added_by=author_id)
49+
.filter(BlockedKarma.topic == item.casefold()).all():
50+
blacklist = BlockedKarma(topic=item.casefold(), user_id=author_id)
5151
db_session.add(blacklist)
5252
db_session.commit()
5353
await ctx.send(f'Added {item} to the karma blacklist. :pencil:')
@@ -58,10 +58,10 @@ async def add(self, ctx: Context, item: str):
5858
@blacklist.command(help="Remove a word from the karma blacklist.")
5959
@is_compsoc_exec()
6060
async def remove(self, ctx: Context, item: str):
61-
if not db_session.query(BlockedKarma).filter(BlockedKarma.name == item.casefold()).all():
61+
if not db_session.query(BlockedKarma).filter(BlockedKarma.topic == item.casefold()).all():
6262
await ctx.send(f'{item} is not in the karma blacklist. :page_with_curl:')
6363
else:
64-
db_session.query(BlockedKarma).filter(BlockedKarma.name == item.casefold()).delete()
64+
db_session.query(BlockedKarma).filter(BlockedKarma.topic == item.casefold()).delete()
6565
db_session.commit()
6666

6767
await ctx.send(f'{item} has been removed from the karma blacklist. :pencil:')
@@ -84,7 +84,7 @@ async def list(self, ctx: Context):
8484
async def search(self, ctx: Context, item: str):
8585
item_folded = item.replace('*', '%').casefold()
8686
items = db_session.query(BlockedKarma) \
87-
.filter(BlockedKarma.name.ilike(f'%{item_folded}%')).all()
87+
.filter(BlockedKarma.topic.ilike(f'%{item_folded}%')).all()
8888
if len(items) == 0:
8989
await ctx.send(
9090
f'There were no topics matching "{item}" in the blacklist. :sweat:')

karma/karma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def process_karma(message: Message, message_id: int, db_session: Session, timeou
124124
karma_item.minuses = karma_item.minuses + 1
125125

126126
# Give some sass if someone is trying to downvote the bot
127-
if transaction.name.lower() == 'apollo' and transaction.net_karma < 0:
127+
if transaction.name.casefold() == 'Apollo'.casefold() and transaction.net_karma < 0:
128128
apollo_response = ':wink:'
129129
else:
130130
apollo_response = ''

karma/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def parse_message(message: str, db_session: Session):
4747
if not (item.group('karma_target').startswith('"') and item.group('karma_target').endswith('"')):
4848
# Check to make sure non quoted item is not in blacklist
4949
if not db_session.query(BlockedKarma)\
50-
.filter(BlockedKarma.name == item.group('karma_target').casefold()).all():
50+
.filter(BlockedKarma.topic == item.group('karma_target').casefold()).all():
5151
results.append(RawKarma(name=item.group('karma_target').replace('"', '').lstrip('@'),
5252
op=item.group('karma_op'),
5353
reason=item.group('karma_reason') or item.group('karma_reason_2')))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Rename blocked karma topic column names
2+
3+
Revision ID: 3e497f4c9795
4+
Revises: fd2fd5c8960d
5+
Create Date: 2018-04-20 12:28:11.497984
6+
7+
"""
8+
from alembic import op
9+
10+
# revision identifiers, used by Alembic.
11+
revision = '3e497f4c9795'
12+
down_revision = 'fd2fd5c8960d'
13+
branch_labels = None
14+
depends_on = None
15+
16+
17+
def upgrade():
18+
op.alter_column('blacklist', column_name='name', new_column_name='topic')
19+
op.alter_column('blacklist', column_name='added_by', new_column_name='user_id')
20+
21+
22+
def downgrade():
23+
pass

models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ class User(Base):
119119
class BlockedKarma(Base):
120120
__tablename__ = 'blacklist'
121121

122-
name = Column(String, primary_key=True, nullable=False)
123-
added_by = Column(Integer, ForeignKey('users.id'), nullable=False)
122+
topic = Column(String, primary_key=True, nullable=False)
123+
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
124124
added_at = Column(DateTime, nullable=False, default=func.current_timestamp())

0 commit comments

Comments
 (0)