Skip to content

Commit e6bccc3

Browse files
committed
Revert "feat: Credit Username on Approval (#162)"
This reverts commit 2e6b2a6.
1 parent 2e6b2a6 commit e6bccc3

File tree

5 files changed

+29
-53
lines changed

5 files changed

+29
-53
lines changed

.github/CHANGELOG.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Show credit username during approval process
10+
### Added
11+
12+
- Add blacklist messages feature as anti-spam
13+
14+
### Changed
15+
16+
- Bump python-telegram-bot to version 22.2
17+
- Bump cryptography to version 45.0.5
18+
- Bump pytz to version 2025.2
19+
- Bump APScheduler to version 3.11.0
20+
21+
### Fixed
22+
23+
- Fix **spam_comment_msg** handler to avoid raising an exception when the message does not contain text
24+
- Ensure message in report has a text
25+
26+
### Changed
1127

12-
...
28+
- Bump python-telegram-bot to version 21.6
29+
- Bump cryptography to version 43.0.1
30+
- Bump PyYAML to version 6.0.2
31+
- Bump pytz to version 2024.2
1332

1433
## [3.1.0] - 2024-02-18
1534

src/spotted/config/db/post_db_init.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ CREATE TABLE IF NOT EXISTS pending_post
55
u_message_id BIGINT NOT NULL,
66
g_message_id BIGINT NOT NULL,
77
admin_group_id BIGINT NOT NULL,
8-
credit_username VARCHAR(255) DEFAULT NULL,
98
message_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
109
PRIMARY KEY (admin_group_id, g_message_id)
1110
);

src/spotted/data/pending_post.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class PendingPost:
1717
u_message_id: id of the original message of the post
1818
g_message_id: id of the post in the group
1919
admin_group_id: id of the admin group
20-
credit_username: username of the user that sent the post if it's a credit post
2120
date: when the post was sent
2221
"""
2322

@@ -26,19 +25,15 @@ class PendingPost:
2625
g_message_id: int
2726
admin_group_id: int
2827
date: datetime
29-
credit_username: str | None = None
3028

3129
@classmethod
32-
def create(
33-
cls, user_message: Message, g_message_id: int, admin_group_id: int, credit_username: str | None = None
34-
) -> "PendingPost":
30+
def create(cls, user_message: Message, g_message_id: int, admin_group_id: int) -> "PendingPost":
3531
"""Creates a new post and inserts it in the table of pending posts
3632
3733
Args:
3834
user_message: message sent by the user that contains the post
3935
g_message_id: id of the post in the group
4036
admin_group_id: id of the admin group
41-
credit_username: username of the user that sent the post if it's a credit post
4237
4338
Returns:
4439
instance of the class
@@ -52,7 +47,6 @@ def create(
5247
u_message_id=u_message_id,
5348
g_message_id=g_message_id,
5449
admin_group_id=admin_group_id,
55-
credit_username=credit_username,
5650
date=date,
5751
).save_post()
5852

@@ -82,7 +76,6 @@ def from_group(cls, g_message_id: int, admin_group_id: int) -> "PendingPost | No
8276
u_message_id=pending_post["u_message_id"],
8377
admin_group_id=pending_post["admin_group_id"],
8478
g_message_id=pending_post["g_message_id"],
85-
credit_username=pending_post["credit_username"],
8679
date=pending_post["message_date"],
8780
)
8881

@@ -108,7 +101,6 @@ def from_user(cls, user_id: int) -> "PendingPost | None":
108101
u_message_id=pending_post["u_message_id"],
109102
admin_group_id=pending_post["admin_group_id"],
110103
g_message_id=pending_post["g_message_id"],
111-
credit_username=pending_post["credit_username"],
112104
date=pending_post["message_date"],
113105
)
114106

@@ -146,15 +138,10 @@ def get_all(admin_group_id: int, before: datetime | None = None) -> list["Pendin
146138

147139
def save_post(self) -> "PendingPost":
148140
"""Saves the pending_post in the database"""
149-
columns = ("user_id", "u_message_id", "g_message_id", "admin_group_id", "message_date")
150-
values = (self.user_id, self.u_message_id, self.g_message_id, self.admin_group_id, self.date)
151-
if self.credit_username is not None:
152-
columns += ("credit_username",)
153-
values += (self.credit_username,)
154141
DbManager.insert_into(
155142
table_name="pending_post",
156-
columns=columns,
157-
values=values,
143+
columns=("user_id", "u_message_id", "g_message_id", "admin_group_id", "message_date"),
144+
values=(self.user_id, self.u_message_id, self.g_message_id, self.admin_group_id, self.date),
158145
)
159146
return self
160147

@@ -173,14 +160,6 @@ def get_votes(self, vote: bool) -> int:
173160
where_args=(self.g_message_id, self.admin_group_id, vote),
174161
)
175162

176-
def get_credit_username(self) -> str | None:
177-
"""Gets the username of the user that credited the post
178-
179-
Returns:
180-
username of the user that credited the post, or None if the post is not credited
181-
"""
182-
return self.credit_username
183-
184163
def get_list_admin_votes(self, vote: "bool | None" = None) -> "list[int] | list[tuple[int, bool]]":
185164
"""Gets the list of admins that approved or rejected the post
186165
@@ -278,6 +257,5 @@ def __repr__(self) -> str:
278257
f"u_message_id: {self.u_message_id}\n"
279258
f"admin_group_id: {self.admin_group_id}\n"
280259
f"g_message_id: {self.g_message_id}\n"
281-
f"credit_username: {self.credit_username}\n"
282260
f"date : {self.date} ]"
283261
)

src/spotted/utils/info_util.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ async def send_post_to_admins(self) -> bool:
334334
admin_group_id = Config.post_get("admin_group_id")
335335
poll = message.poll # if the message is a poll, get its reference
336336

337-
user = User(self.user_id)
338-
credit_username: str | None = None
339-
if user.is_credited:
340-
chat = await self.bot.get_chat(self.chat_id)
341-
if chat.username:
342-
credit_username = chat.username
343337
try:
344338
if poll: # makes sure the poll is anonym
345339
g_message = await self.__bot.send_poll(
@@ -349,14 +343,14 @@ async def send_post_to_admins(self) -> bool:
349343
type=poll.type,
350344
allows_multiple_answers=poll.allows_multiple_answers,
351345
correct_option_id=poll.correct_option_id,
352-
reply_markup=get_approve_kb(credited_username=credit_username),
346+
reply_markup=get_approve_kb(),
353347
)
354348
elif message.text and message.entities: # maintains the previews, if present
355349
show_preview = self.user_data.get("show_preview", True)
356350
g_message = await self.__bot.send_message(
357351
chat_id=admin_group_id,
358352
text=message.text,
359-
reply_markup=get_approve_kb(credited_username=credit_username),
353+
reply_markup=get_approve_kb(),
360354
entities=message.entities,
361355
link_preview_options=LinkPreviewOptions(not show_preview),
362356
)
@@ -365,18 +359,13 @@ async def send_post_to_admins(self) -> bool:
365359
chat_id=admin_group_id,
366360
from_chat_id=message.chat_id,
367361
message_id=message.message_id,
368-
reply_markup=get_approve_kb(credited_username=credit_username),
362+
reply_markup=get_approve_kb(),
369363
)
370364
except BadRequest as ex:
371365
logger.error("Sending the post on send_post_to: %s", ex)
372366
return False
373367

374-
PendingPost.create(
375-
user_message=message,
376-
admin_group_id=admin_group_id,
377-
g_message_id=g_message.message_id,
378-
credit_username=credit_username,
379-
)
368+
PendingPost.create(user_message=message, admin_group_id=admin_group_id, g_message_id=g_message.message_id)
380369

381370
return True
382371

src/spotted/utils/keyboard_util.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def get_settings_kb() -> InlineKeyboardMarkup:
5757
)
5858

5959

60-
def get_approve_kb(
61-
pending_post: PendingPost = None, approve: int = -1, reject: int = -1, credited_username: str | None = None
62-
) -> InlineKeyboardMarkup:
60+
def get_approve_kb(pending_post: PendingPost = None, approve: int = -1, reject: int = -1) -> InlineKeyboardMarkup:
6361
"""Generates the InlineKeyboard for the pending post.
6462
If the pending post is None, the keyboard will be generated with 0 votes.
6563
Otherwise, the keyboard will be generated with the correct number of votes.
@@ -70,7 +68,6 @@ def get_approve_kb(
7068
pending_post: existing pending post to which the keyboard is attached
7169
approve: number of approve votes known in advance
7270
reject: number of reject votes known in advance
73-
credited_username: username of the user who credited the post if it was credited
7471
7572
Returns:
7673
new inline keyboard
@@ -81,14 +78,8 @@ def get_approve_kb(
8178
else:
8279
n_approve = pending_post.get_votes(vote=True) if approve < 0 else approve
8380
n_reject = pending_post.get_votes(vote=False) if reject < 0 else reject
84-
credited_username = pending_post.get_credit_username()
8581
return InlineKeyboardMarkup(
8682
[
87-
(
88-
[]
89-
if credited_username is None
90-
else [InlineKeyboardButton(f"👤 {credited_username}", callback_data="none")]
91-
),
9283
[
9384
InlineKeyboardButton(f"🟢 {n_approve}", callback_data="approve_yes"),
9485
InlineKeyboardButton(f"🔴 {n_reject}", callback_data="approve_no"),

0 commit comments

Comments
 (0)