Skip to content

Commit

Permalink
chore: review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LightDestory committed Jan 3, 2024
1 parent 13829ca commit af20afb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/spotted/config/db/post_db_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CREATE TABLE IF NOT EXISTS warned_users
(
user_id BIGINT NOT NULL,
warn_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
valid_until_date TIMESTAMP NOT NULL,
expire_date TIMESTAMP NOT NULL,
PRIMARY KEY (user_id, warn_date)
);
-----
Expand Down Expand Up @@ -91,5 +91,5 @@ CREATE TRIGGER IF NOT EXISTS drop_old_warns
BEFORE INSERT ON warned_users
FOR EACH ROW
BEGIN
DELETE FROM warned_users WHERE user_id=NEW.user_id and valid_until_date < DATETIME('now');
DELETE FROM warned_users WHERE user_id=NEW.user_id and expire_date < DATETIME('now');
END;
4 changes: 2 additions & 2 deletions src/spotted/data/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ async def unmute(self, bot: Bot | None):

def warn(self):
"""Increase the number of warns of a user
If this is number would reach 3 the user is banned
If the number of warns is greater than the maximum allowed, the user is banned
Args:
bot: the telegram bot
"""
valid_until_date = datetime.now() + timedelta(days=Config.post_get("warn_expiration_days"))
DbManager.insert_into(
table_name="warned_users", columns=("user_id", "valid_until_date"), values=(self.user_id, valid_until_date)
table_name="warned_users", columns=("user_id", "expire_date"), values=(self.user_id, valid_until_date)
)

def become_anonym(self) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions src/spotted/handlers/mute.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ async def mute_cmd(update: Update, context: CallbackContext):
except ValueError:
pass
user = User(g_message.from_user.id)
mute_days_text = f"{days} giorn{'o' if days == 1 else 'i'}"
await user.mute(info.bot, days)
await info.bot.send_message(
chat_id=Config.post_get("admin_group_id"),
text=f"L'utente {user.user_id} è stato mutato per {days} giorn{'o' if days == 1 else 'i'}.",
text=f"L'utente {user.user_id} è stato mutato per {mute_days_text}.",
)
await info.bot.send_message(
chat_id=user.user_id, text=f"Sei stato mutato da Spotted DMI" f"per {days} giorn{'o' if days == 1 else 'i'}"
chat_id=user.user_id, text=f"Sei stato mutato da Spotted DMI per {mute_days_text}."
)
await info.message.delete()

0 comments on commit af20afb

Please sign in to comment.