2023-04-05 04:33:29 +00:00
|
|
|
from config import Config
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import MessageSession
|
2022-01-08 07:17:21 +00:00
|
|
|
from database import BotDBUtil
|
2021-10-18 15:50:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def warn_target(msg: MessageSession, reason=None):
|
|
|
|
current_warns = int(msg.target.senderInfo.query.warns) + 1
|
|
|
|
msg.target.senderInfo.edit('warns', current_warns)
|
2023-03-05 11:15:44 +00:00
|
|
|
warn_template = [msg.locale.t("tos.warning")]
|
2021-10-18 15:50:46 +00:00
|
|
|
if reason is not None:
|
2023-03-05 11:15:44 +00:00
|
|
|
warn_template.append(msg.locale.t("tos.reason") + reason)
|
2021-10-20 14:04:30 +00:00
|
|
|
if current_warns < 5:
|
2023-03-05 11:15:44 +00:00
|
|
|
warn_template.append(msg.locale.t('tos.warning.count', current_warns=current_warns))
|
2021-10-20 14:04:30 +00:00
|
|
|
if current_warns <= 2:
|
2023-04-05 04:33:29 +00:00
|
|
|
warn_template.append(msg.locale.t('tos.warning.appeal', issue_url=Config('issue_url')))
|
2021-10-20 14:04:30 +00:00
|
|
|
if current_warns == 5:
|
2023-03-05 11:15:44 +00:00
|
|
|
warn_template.append(msg.locale.t('tos.warning.last'))
|
2021-10-20 14:04:30 +00:00
|
|
|
if current_warns > 5:
|
2021-11-15 16:26:11 +00:00
|
|
|
msg.target.senderInfo.edit('isInBlockList', True)
|
2021-10-18 15:50:46 +00:00
|
|
|
return
|
|
|
|
await msg.sendMessage('\n'.join(warn_template))
|
2022-01-08 07:17:21 +00:00
|
|
|
|
2022-01-08 08:08:25 +00:00
|
|
|
|
2022-01-08 07:17:21 +00:00
|
|
|
async def pardon_user(user: str):
|
|
|
|
BotDBUtil.SenderInfo(user).edit('warns', 0)
|
|
|
|
|
2022-01-08 08:08:25 +00:00
|
|
|
|
2022-01-08 07:17:21 +00:00
|
|
|
async def warn_user(user: str, count=1):
|
|
|
|
current_warns = int(BotDBUtil.SenderInfo(user).query.warns) + count
|
|
|
|
BotDBUtil.SenderInfo(user).edit('warns', current_warns)
|
|
|
|
if current_warns > 5:
|
|
|
|
BotDBUtil.SenderInfo(user).edit('isInBlockList', True)
|
|
|
|
return current_warns
|