def do_change_bot_owner(user_profile: UserProfile, bot_owner: UserProfile, acting_user: UserProfile) -> None:
    previous_owner = user_profile.bot_owner
    user_profile.bot_owner = bot_owner
    user_profile.save()
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user, modified_user=user_profile, event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED, event_time=event_time)
    update_users = bot_owner_user_ids(user_profile)
    if (previous_owner and (not previous_owner.is_realm_admin)):
        send_event(user_profile.realm, dict(type='realm_bot', op='delete', bot=dict(user_id=user_profile.id)), {previous_owner.id})
        update_users = (update_users - {previous_owner.id})
    if (not bot_owner.is_realm_admin):
        add_event = created_bot_event(user_profile)
        send_event(user_profile.realm, add_event, {bot_owner.id})
        update_users = (update_users - {bot_owner.id})
    send_event(user_profile.realm, dict(type='realm_bot', op='update', bot=dict(user_id=user_profile.id, owner_id=user_profile.bot_owner.id)), update_users)
    event: Dict[(str, Any)] = dict(type='realm_user', op='update', person=dict(user_id=user_profile.id, bot_owner_id=user_profile.bot_owner.id))
    send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))
def do_change_bot_owner(user_profile: UserProfile, bot_owner: UserProfile, acting_user: UserProfile) -> None:
    previous_owner = user_profile.bot_owner
    user_profile.bot_owner = bot_owner
    user_profile.save()
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user, modified_user=user_profile, event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED, event_time=event_time)
    update_users = bot_owner_user_ids(user_profile)
    if (previous_owner and (not previous_owner.is_realm_admin)):
        send_event(user_profile.realm, dict(type='realm_bot', op='delete', bot=dict(user_id=user_profile.id)), {previous_owner.id})
        update_users = (update_users - {previous_owner.id})
    if (not bot_owner.is_realm_admin):
        add_event = created_bot_event(user_profile)
        send_event(user_profile.realm, add_event, {bot_owner.id})
        update_users = (update_users - {bot_owner.id})
    send_event(user_profile.realm, dict(type='realm_bot', op='update', bot=dict(user_id=user_profile.id, owner_id=user_profile.bot_owner.id)), update_users)
    event: Dict[(str, Any)] = dict(type='realm_user', op='update', person=dict(user_id=user_profile.id, bot_owner_id=user_profile.bot_owner.id))
    send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))