コード例 #1
0
 def get_chat(self) -> dict:
     result = json.loads(fast_req.get(
         f'https://api.telegram.org/bot{settings.GROUP}/getChat?chat_id={self.database.chat_id}'
     )['body'])['result']
     if result.get('first_name'):
         result['first_name'] = functions.clear_name(result['first_name'])
     return result
コード例 #2
0
 def noadd(self, user):
     force_add = self.get_add(user.database)
     force_add.promoted = True
     force_add.save()
     self.restrict_chat_member(user.database.chat_id, self.get_chat()['permissions'])
     self.send_message(
         self.translate('noadd', functions.clear_name(user.get_chat()['first_name']), user.database.chat_id),
         parse_mode='Markdown'
     )
コード例 #3
0
 def kick_chat_member(self, user_id: int, first_name: str, reason: str, until_date: float = '', /):
     fast_req.get(
         f'https://api.telegram.org/bot{settings.GROUP}/kickChatMember?chat_id={self.database.chat_id}&'
         f'user_id={user_id}&until_date={until_date}'
     )
     for message in self.get_messages(40, User(user_id).database):
         self.delete_message(message.message_unique_id)
         message.delete()
     self.send_message(self.translate('ban', functions.clear_name(first_name), reason))
コード例 #4
0
 def clear(self, from_user: dict, /):
     warn, created = models.Warn.objects.get_or_create(user=User(from_user['id']).database, group=self.database)
     from_user['first_name'] = functions.clear_name(from_user['first_name'])
     if warn.count > 0:
         warn.count = 0
         self.send_message(self.translate('clear', from_user['first_name'], from_user['id']), parse_mode='Markdown')
         warn.save()
     else:
         self.send_message(
             self.translate('no_warn', from_user['first_name'], from_user['id']), parse_mode='Markdown'
         )
コード例 #5
0
            activity.messages.add(activity_message)
            if (current_time - activity.last_message).seconds >= self.database.spam_time:
                activity.count = 1
                activity.last_message = current_time
                activity.messages.clear()
                activity.save()
            else:
                activity.last_message = current_time
                if activity.count >= self.database.max_messages:
                    activity.count = 0
                    activity.restricted = True
                    activity.save()
                    for activity_message in activity.messages.all():
                        self.delete_message(activity_message.message_unique_id)
                    activity.messages.all().delete()
                    message['from']['first_name'] = functions.clear_name(message['from']['first_name'])
                    if self.database.spam_punish == 'b':
                        self.kick_chat_member(user.chat_id, message['from']['first_name'], self.translate('spamming'))
                    else:
                        self.restrict_chat_member(user.chat_id, {'can_send_messages': False})
                        self.send_message(
                            self.translate('spam', message['from']['first_name'], user.chat_id), parse_mode='Markdown'
                        )
                else:
                    activity.save()

    def check_report(self, message_id: int, message_unique_id: int, user: models.User):
        message, created = models.Message.objects.get_or_create(
            message_unique_id=message_unique_id, group=self.database
        )
        if user not in message.reporters.all():