예제 #1
0
    def insert_flood(self, data: CacheModel, message: Message, database: dict):
        ex = (
            convert_time(database["time"])
            if database.get("time") is not None
            else None
        )

        return bredis.set(self.cache_key(message), pickle.dumps(data), ex=ex)
예제 #2
0
 def set_state(self, message: Message):
     return bredis.set(self.state_cache_key.format(chat_id=message.chat.id),
                       message.from_user.id)
예제 #3
0
                'admin': True,
                'title': admin['custom_title'],
                'anonymous': admin['is_anonymous'],
                'can_change_info': admin['can_change_info'],
                'can_delete_messages': admin['can_delete_messages'],
                'can_invite_users': admin['can_invite_users'],
                'can_restrict_members': admin['can_restrict_members'],
                'can_pin_messages': admin['can_pin_messages'],
                'can_promote_members': admin['can_promote_members']
            }

            with suppress(KeyError):  # Optional permissions
                alist[user_id]['can_post_messages'] = admin[
                    'can_post_messages']

        bredis.set(key, pickle.dumps(alist))
        bredis.expire(key, 900)
    return alist


async def is_user_admin(chat_id, user_id):
    # User's pm should have admin rights
    if chat_id == user_id:
        return True

    if user_id in OPERATORS:
        return True

    # Workaround to support anonymous admins
    if user_id == 1087968824:
        return True
예제 #4
0
async def set_value(key, value, ttl):
    value = pickle.dumps(value)
    bredis.set(key, value)
    if ttl:
        bredis.expire(key, ttl)