Добавлена возможность запретить поздравлять себя с днем рождения.
This commit is contained in:
parent
7578ad00c8
commit
c73f9cb522
2 changed files with 29 additions and 1 deletions
26
bot.py
26
bot.py
|
|
@ -51,7 +51,7 @@ MESSAGE_NEED_REPLY = 'Извините, но эту команду нужно в
|
||||||
MESSAGE_DEFAULT_RULES = 'Правила не установлены. Просто ведите себя хорошо.'
|
MESSAGE_DEFAULT_RULES = 'Правила не установлены. Просто ведите себя хорошо.'
|
||||||
MESSAGE_DEFAULT_GREETING_JOIN = 'Добро пожаловать, {name}!'
|
MESSAGE_DEFAULT_GREETING_JOIN = 'Добро пожаловать, {name}!'
|
||||||
MESSAGE_DEFAULT_GREETING_REJOIN = 'С возвращением, {name}!'
|
MESSAGE_DEFAULT_GREETING_REJOIN = 'С возвращением, {name}!'
|
||||||
MESSAGE_DEFAULT_BIRTHDAY = 'Сегодня {name} празднует День Рождения!\nПоздравляем!\n@all'
|
MESSAGE_DEFAULT_BIRTHDAY = 'Сегодня {name} празднует День Рождения!\nПоздравляю!'
|
||||||
|
|
||||||
|
|
||||||
@bot.on.chat_message(text="!помощь")
|
@bot.on.chat_message(text="!помощь")
|
||||||
|
|
@ -68,6 +68,7 @@ async def rules_handler(message: Message):
|
||||||
response += '!месяц - статистика сообщений за месяц\n'
|
response += '!месяц - статистика сообщений за месяц\n'
|
||||||
response += '!молчуны - список молчунов\n'
|
response += '!молчуны - список молчунов\n'
|
||||||
response += '!предупреждения - список участников с предупреждениями\n'
|
response += '!предупреждения - список участников с предупреждениями\n'
|
||||||
|
response += '!поздравление - запретить/разрешить поздравлять с днем рождения\n'
|
||||||
response += '\n'
|
response += '\n'
|
||||||
response += bold('Команды для администраторов') + '\n'
|
response += bold('Команды для администраторов') + '\n'
|
||||||
response += '!старт - начать работу в чате\n'
|
response += '!старт - начать работу в чате\n'
|
||||||
|
|
@ -342,6 +343,25 @@ async def silent_handler(message: Message):
|
||||||
await message.answer(response)
|
await message.answer(response)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on.chat_message(text="!поздравление")
|
||||||
|
async def no_birthday_handler(message: Message):
|
||||||
|
chat_id = message.peer_id
|
||||||
|
chat = create_chat_if_not_exists(chat_id)
|
||||||
|
if chat['active'] == 0:
|
||||||
|
await message.answer(MESSAGE_CHAT_NOT_ACTIVE)
|
||||||
|
return
|
||||||
|
|
||||||
|
user_id = message.from_id
|
||||||
|
user = create_user_if_not_exists(chat_id, user_id)
|
||||||
|
happy_birthday = 1 if user['happy_birthday'] == 0 else 0
|
||||||
|
database.DB.user_toggle_happy_birthday(chat_id, user_id, happy_birthday)
|
||||||
|
|
||||||
|
if happy_birthday == 1:
|
||||||
|
await message.answer('Хорошо, я буду поздравлять тебя с днем рождения, если его дата не скрыта.')
|
||||||
|
else:
|
||||||
|
await message.answer('Хорошо, я не буду поздравлять тебя с днем рождения.')
|
||||||
|
|
||||||
|
|
||||||
@bot.on.chat_message(action=['chat_invite_user', 'chat_invite_user_by_link'])
|
@bot.on.chat_message(action=['chat_invite_user', 'chat_invite_user_by_link'])
|
||||||
async def user_join_handler(message: Message):
|
async def user_join_handler(message: Message):
|
||||||
chat_id = message.peer_id
|
chat_id = message.peer_id
|
||||||
|
|
@ -423,6 +443,10 @@ async def check_birthdays():
|
||||||
if member.id < 0 or member.bdate is None:
|
if member.id < 0 or member.bdate is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
user = database.DB.get_user(chat_id, member.id)
|
||||||
|
if user['happy_birthday'] == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
parts = member.bdate.split('.')
|
parts = member.bdate.split('.')
|
||||||
if len(parts) < 2:
|
if len(parts) < 2:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class Database:
|
||||||
"messages_today" INTEGER NOT NULL DEFAULT 0,
|
"messages_today" INTEGER NOT NULL DEFAULT 0,
|
||||||
"messages_month" INTEGER NOT NULL DEFAULT 0,
|
"messages_month" INTEGER NOT NULL DEFAULT 0,
|
||||||
"warnings" INTEGER NOT NULL DEFAULT 0,
|
"warnings" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
"happy_birthday" INTEGER NOT NULL DEFAULT 1,
|
||||||
PRIMARY KEY("chat_id","user_id"))
|
PRIMARY KEY("chat_id","user_id"))
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
@ -71,6 +72,9 @@ class Database:
|
||||||
def user_increment_warnings(self, chat_id: int, user_id: int):
|
def user_increment_warnings(self, chat_id: int, user_id: int):
|
||||||
self.user_increment(chat_id, user_id, ['warnings'])
|
self.user_increment(chat_id, user_id, ['warnings'])
|
||||||
|
|
||||||
|
def user_toggle_happy_birthday(self, chat_id: int, user_id: int, happy_birthday: int):
|
||||||
|
self.user_update(chat_id, user_id, happy_birthday=happy_birthday)
|
||||||
|
|
||||||
def user_increment(self, chat_id: int, user_id: int, fields: List[str]):
|
def user_increment(self, chat_id: int, user_id: int, fields: List[str]):
|
||||||
self.cursor.execute("UPDATE users SET " + ", ".join(f + " = " + f + " + 1" for f in fields) +
|
self.cursor.execute("UPDATE users SET " + ", ".join(f + " = " + f + " + 1" for f in fields) +
|
||||||
" WHERE chat_id = ? AND user_id = ?", (chat_id, user_id))
|
" WHERE chat_id = ? AND user_id = ?", (chat_id, user_id))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue